Hello,
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.
Dim vInput
vInput = InputBox("Shut down how many servers?")
If CInt(vInput) = vInput Then
'Shut them down
Else
MsgBox "You didn't type a whole number."
End If
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. "