VBS script question
I'm trying to learn VBS scripting and I'm reading this Ebook called "Managing Windows with VB Script and WMI". I copied the code below from the Ebook and it's not working. I don't know if this is an error on the authors part. The script is supposed to do error checking to make sure that the user isn't entering a fraction. Whenever I launch this script it keeps on telling me that I'm not entering a whole number number when I type in whole numbers. For example if I type 9 then the VBS script displays a message box saying "You didn't type a whole number". I thought that maybe it was because I didn't have any code within the If statement so I replaced ('Shut them down) with (msgbox "You got it") and it still didn't work.
This is the whole section of the book that I'm stuck on.
" You'll often use these functions to convert user input to a specific data type. For example, if you have an input box that accepts the number of servers to shut down, you want to make sure that's a whole number, and not some fractional number, because a fraction wouldn't make sense. You might use something like this.
vInput = InputBox("Shut down how many servers?")
If CInt(vInput) = vInput Then
'Shut them down
MsgBox "You didn't type a whole number."
In this case, I used CInt() to force vInput to be an integer, and then compared the result to the original value in vInput. If the two were the same, the original input was an integer and the script continues. If not, the script displays an error message and ends. "
I'm probably wrong but should there not be a msgbox before the first text and should it not be in quotes like the second. The error would probably be because the if statement would not be correct as it would be expecting that statement before else, as it is, its just a comment with the '
Then again I could be completely wrong!
Originally Posted by TechSupp
I really don't get what you're saying. I removed the comment and put a MSGBOX command there and it still didn't work.
Linky -> http://www.vbforums.com/showthread.p...-Whole-Numbers
Numeric = InputBox("Please enter a whole number!")
if Numeric=int(Numeric) then
MsgBox "A whole number was entered"
MsgBox "Please enter a whole number"