subtracting decimal values in textboxes
-
Hi everyone, Can someone help me with following code Dim temp1 as decimal dim temp2 as decimal dim result as decimal temp1 = CDec(txtvalue1.text).tostring("N4") temp2 = Cdec(txtvalue2.text).tostring("N4") result = temp1-temp2 txtfinalvalue.text = Cstr(result) what is wrong in the above code? I have decimal values in two textboxes and I need to subtract them and display the result as a decimal value into the third textbox. thankyou all in advance Aartee. ...HE is watching Us All! -- modified at 21:50 Wednesday 14th September, 2005
-
Hi everyone, Can someone help me with following code Dim temp1 as decimal dim temp2 as decimal dim result as decimal temp1 = CDec(txtvalue1.text).tostring("N4") temp2 = Cdec(txtvalue2.text).tostring("N4") result = temp1-temp2 txtfinalvalue.text = Cstr(result) what is wrong in the above code? I have decimal values in two textboxes and I need to subtract them and display the result as a decimal value into the third textbox. thankyou all in advance Aartee. ...HE is watching Us All! -- modified at 21:50 Wednesday 14th September, 2005
BORN...again! wrote: temp1 = CDec(txtvalue1.text).tostring("N4") temp2 = Cdec(txtvalue2.text).tostring("N4") r Change this to:
temp1 = CDec(txtvalue1.text)
temp2 = Cdec(txtvalue2.text)...Steve
-
BORN...again! wrote: temp1 = CDec(txtvalue1.text).tostring("N4") temp2 = Cdec(txtvalue2.text).tostring("N4") r Change this to:
temp1 = CDec(txtvalue1.text)
temp2 = Cdec(txtvalue2.text)...Steve
Hi Steve, Thankyou for your prompt help. I tried it like you said but i still get the error as "System.InvalidCastException: Cast from string "" to type 'Decimal' is not valid." Any more tips? thanks a ton Aartee. ...HE is watching Us All!
-
Hi Steve, Thankyou for your prompt help. I tried it like you said but i still get the error as "System.InvalidCastException: Cast from string "" to type 'Decimal' is not valid." Any more tips? thanks a ton Aartee. ...HE is watching Us All!
One of those textboxes doesn't have anything in it when this code runs. Put those two CDel lines in seperate Try/Catch blocks to make sure the values are filled in with 0 if the strings enter into the textbox's are not valid numbers.
Try
value1 = CDel(textbox1.Text)
Catch
value1 = 0
End TryRageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
Hi Steve, Thankyou for your prompt help. I tried it like you said but i still get the error as "System.InvalidCastException: Cast from string "" to type 'Decimal' is not valid." Any more tips? thanks a ton Aartee. ...HE is watching Us All!
Dave is correct. You need to ensure the data being converted is valid before the conversion takes place otherwise an exception can be thrown. ...Steve
-
Dave is correct. You need to ensure the data being converted is valid before the conversion takes place otherwise an exception can be thrown. ...Steve
Thanks guys, I initialised the values of the variables and Bingo!thanks for all the help. Aartee. ...HE is watching Us All!