You could use the
cInt function like this:
' use cInt function
Dim myHotkey : Set myHotkey =
Keyboard.RegisterHotkey("Alt-Control-Shift-I","Funct")
Function Funct()
Number = 5
Taken = InputBox( "Enter a number: " )
Taken = cInt(Taken)
If Taken = Number Then MsgBox "Yep! There you got it."
If Taken <> Number Then MsgBox "That was a blow!"
End Function
The inputBox is getting a string, and the cInt function converts it to
an integer.
Of course, you would need to bullet proof the script to prevent errors
if the user entered something other that a number.
Hope this helps,
Jeff Weiss
From: David [mailto:[email protected]]
Sent: Thursday, December 17, 2009 1:04 PM
To: Scripting List WE
Subject: VBS Converting strings to numbers
I have a VB script which goes like this:
Taken = InputBox( "Enter a number: " )
If Taken = Number Then MsgBox "Yep! There you got it."
If Taken <> Number Then MsgBox "That was a blow!"
Number is a Numeric value, randomly set earlier in the script.
Even if I make sure to enter the CORRECT value into the editbox - in
other words into the variable Taken, the script keeps giving me the
"That was a blow!" message. I can't get it to accept that the Taken and
Number values are equal.
I do wonder, if the returned value from the InputBox is a String format?
If so, I guess I have to (somehow) convert it into a Numeric format,
before I can do the comparison. Am I on the track of something? If so,
how do I do the conversion of a String into a Numeric?
And, first we are doing that, what is the way to convert a Numeric into
a String?
Hope this makes sense, and that someone could point me in the right
direction. Thanks!