Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding Numbers from a text field 1

Status
Not open for further replies.

happyb

Programmer
Oct 25, 2000
29
AU
I have looked all over the forums for the answer to my question, but I cannot find anything. I am kinda new to ASP so this may be obvious to you all. So if anyone can help me it would be appreciated.

I am trying to add two numbers. One comes from a form field the other comes from a database record. I am trying to add on to the database record the number in the form field.

eg...if the form field has a value of 1 and the database had a value of 20, the new database value would be 21

I have a form, with a field that holds the number.
input type='text' name= 'getnumber' value = '1'

The form action goes to the next page where I dim StrGetNumber and give it the value of the form field (getnumber).

On the current page, I collect the current totol from the database...response.write(rs("total"))

Now I want to add these up so I use...
Dim NewTotal
NewTotal = rs("total") + StrGetNumber

Now instead of getting a new total of 21...I get a value of 201...meaning that it is appending the value of the form field and not adding it to the total.

I am sure that it is just a syntax problem, but as I said I looked all over the place before posting this message.

Please help if you can,

Happyb


 
Try explicitly making your strings into numbers:

NewTotal = CInt(rs("total")) + CInt(StrGetNumber)

CInt is for integers, for numbers with decimals try CDbl or CLng
 
It WORKED!!!


Thank you thank you thank you!

Very Happyb
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top