Click to See Complete Forum and Search --> : VBScript: Converting string to a number


SteveS
October 22nd, 2001, 12:56 PM
I have a number in string format that my VBScript won't treat as a number.

For example:


myVar = "100"
If mVar >= 100 then
:
:




I get an error on the "If" line. I program in C++ all the time so I completely understand the difference between "100" and 100, but what I don't understand is when this bizarre VBScript and its VARIANT datatype will do this or that for me.

So, my simple question is how do I convert this into a number? I checked the MSDN and I swear that Microsoft couldn't design a more difficult documentation package than the MSDN if they tried!

DSJ
October 22nd, 2001, 01:06 PM
Try:

Somevar = "100"

if CInt(somevar) <= 100 then
....

SteveS
October 22nd, 2001, 01:09 PM
Doesn't work. I get:


Microsoft VBScript runtime error '800a000d'

Type mismatch: 'CInt'

/myfile.asp, line 29

Iouri
October 22nd, 2001, 01:14 PM
I tried the following code and it works fine

dim a
a= "100"
if a>90 then msgbox "greater"

check theat you have the write version of Internet Explorer. I believe it must work with IE 5 +

Iouri Boutchkine
iouri@hotsheet.com

SteveS
October 22nd, 2001, 01:18 PM
I think the server might still be a IE 4 system. What is the solution if I have such an old server?

Iouri
October 22nd, 2001, 01:44 PM
First solution is to upgrade (it is free)
Second - in VBS all the variables are variant. There are no strings or numbers. Try to enter you var
instead a ="100"
try a = 100

I am not sure, but it might help


Iouri Boutchkine
iouri@hotsheet.com

rshekhar
October 22nd, 2001, 09:27 PM
Try with this


<%


dim myString

myString = "100"

if Cint(myString) <= 100 then
...........
else
...........
end if

%>

its working, try this also CLng,CDbl,CSng

Shekhar

SteveS
October 23rd, 2001, 06:26 AM
Thanks for the replay, but for some reason I get scripting errors with the function CInt. From someone else's comment, I think my problem has to do with using an old 4.X version of Internet Explorer.