|
-
October 22nd, 2001, 12:56 PM
#1
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!
Why are the "tolerant" so easy to offend?
-
October 22nd, 2001, 01:06 PM
#2
Re: VBScript: Converting string to a number
Try:
Somevar = "100"
if CInt(somevar) <= 100 then
....
-
October 22nd, 2001, 01:09 PM
#3
Re: VBScript: Converting string to a number
Doesn't work. I get:
Microsoft VBScript runtime error '800a000d'
Type mismatch: 'CInt'
/myfile.asp, line 29
Why are the "tolerant" so easy to offend?
-
October 22nd, 2001, 01:14 PM
#4
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]
-
October 22nd, 2001, 01:18 PM
#5
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?
Why are the "tolerant" so easy to offend?
-
October 22nd, 2001, 01:44 PM
#6
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]
-
October 22nd, 2001, 09:27 PM
#7
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
-
October 23rd, 2001, 06:26 AM
#8
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.
Why are the "tolerant" so easy to offend?
-
July 5th, 2017, 01:53 PM
#9
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...
-
July 5th, 2017, 08:35 PM
#10
Re: VBScript: Converting string to a number
I would think after 16 years the problem has either been solved or forgotten
Always use [code][/code] tags when posting code.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|