VBScript: Converting string to a number
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!
Re: VBScript: Converting string to a number
Try:
Somevar = "100"
if CInt(somevar) <= 100 then
....
Re: VBScript: Converting string to a number
Doesn't work. I get:
Microsoft VBScript runtime error '800a000d'
Type mismatch: 'CInt'
/myfile.asp, line 29
Re: VBScript: Converting string to a number
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
[email protected]
Re: VBScript: Converting string to a number
I think the server might still be a IE 4 system. What is the solution if I have such an old server?
Re: VBScript: Converting string to a number
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
[email protected]
Re: VBScript: Converting string to a number
Try with this
<%
dim myString
myString = "100"
if Cint(myString) <= 100 then
...........
else
...........
end if
%>
its working, try this also CLng,CDbl,CSng
Shekhar
Re: VBScript: Converting string to a number
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.
Re: VBScript: Converting string to a number
You may use
dim myString
myString=""
if Cint(myString) < 100 then
...........
else
...........
end if
then you get scripting errors with the function CInt.
now try this one
if Cint( "0"&myString) < 100 then
...........
else
...........
end if
This works. I tested it.
Rara...
Re: VBScript: Converting string to a number
I would think after 16 years the problem has either been solved or forgotten ;)