# [web] ASP : Concerning strings recieved from forms

This topic is 4775 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Having a slight ASP (VBSCRIPT) problem, and all I want to do is something really simple. Basically just want to convert the data i get from request.form into numeric, as currently when doing the following: testvar1=request.form("test1") testvar2=request.form("test1") testvar3=(testvar1+testvar2) it just puts the one number after the other so say the two bits of data is 1 and 2 it will display 12 not 3 however if I do this testvar3=(testvar1+10) it adds them up correctly. Hope thats enough information sorry for the really simple question, just me being retarded. (i'v played with formatnumber but that just goes 1.002.00) Thanks in advance

##### Share on other sites
This has to do with how variants and strongly typed variables are handled (which goes beyond the scope of your specific issue). To solve this, just implicitly cast the values as integers (the 10 is already implicited cast, which is why it causes an integer addition). To cast to integer use CLng() (cast as long integer [32bit integer]). Some of the more useful casting functions include CDble (cast as double), CBool (cast as boolean), CDate (cast as datetime) and CCur (cast as currency [a non-lossy fixed floating point value])

testvar1=CLng(request.form("test1"))testvar2=CLng(request.form("test1"))testvar3=(testvar1+testvar2)

##### Share on other sites
I havent used ASP but in VB there are functions to do type conversion. If your values are integers then you might be looking for CInt().

testvar1=CInt(request.form("test1"))
testvar2=CInt(request.form("test1"))
testvar3=(testvar1+testvar2)

*Curses! Beaten!

##### Share on other sites
CInt is another casting function (there are cast functions all types, for instance in addition to CDble there is CSng [Single]). The only issue is that unless you are casting for a binary save operation, CInt is more limiting then CLng because it will actually cast the value as a 16 bit integer (maximum value 32768)

##### Share on other sites

It works now :)

Thank you so much

1. 1
2. 2
Rutin
21
3. 3
JoeJ
18
4. 4
5. 5

• 14
• 40
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631722
• Total Posts
3001892
×