Jump to content
  • Advertisement
Sign in to follow this  
drackill

[web] ASP : Concerning strings recieved from forms

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!