Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi, how convert textbox value to integer. i need get avarage when i enter value into text box.my code like this
dim nn as double
nn=textbox1.text
dim kk as double
kk=textbox2. text
textb
kk=nn\4
then i got erro msg. its `canont convert string to type double is not valied.
then i try like that
dim ll as double
ll= textbox1.text
textbox2.text= ll\ 4
its work.
but display result is not as a double
when i enter 5 to textbox1 and then click button. result is 1. not 1.25
its not possiible to average
please correct ma code or help me .
im using vb.net
thanks
Posted

You are using wrong operator.

The \ Operator returns the integer quotient of a division. For example, the expression 14 \ 4 evaluates to 3.
The / Operator (Visual Basic) returns the full quotient, including the remainder, as a floating-point number. For example, the expression 14 / 4 evaluates to 3.5.

Ref:http://msdn.microsoft.com/en-us/library/se0w9esz(v=vs.80).aspx[^]
 
Share this answer
 
Comments
Abhinav S 7-Feb-12 1:48am    
Good catch. My 5.
Prerak Patel 7-Feb-12 2:07am    
Thanks Abhinav
Amal anjula 7-Feb-12 2:51am    
tax u dr.its wrkd
Try kk=CDbl(nn)/4 .
You should not get the error.

Do the same thing for other calculations as well.
 
Share this answer
 
v2
Comments
Prerak Patel 7-Feb-12 2:08am    
Man, nn is already declared as double. CDbl won't serve anything. When the text is assigned to double, it is implicitly converted I guess.
Abhinav S 7-Feb-12 3:39am    
Agreed.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900