Scripts Thread, VBS script question in Coding and Web Development; Hello,
I'm trying to learn VBS scripting and I'm reading this Ebook called "Managing Windows with VB Script and WMI". ...
22nd April 2013, 06:46 PM #1
- Rep Power
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. "
Last edited by bill23077; 22nd April 2013 at 06:48 PM.
IDG Tech News
22nd April 2013, 07:51 PM #2
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!
22nd April 2013, 08:46 PM #3
- Rep Power
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.
Last edited by bill23077; 22nd April 2013 at 08:47 PM.
22nd April 2013, 09:12 PM #4
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"
By markesmith in forum Scripts
Last Post: 26th April 2007, 04:03 PM
By ajbritton in forum Coding
Last Post: 27th December 2006, 10:16 PM
By contink in forum Scripts
Last Post: 25th December 2006, 10:15 PM
By tosca925 in forum How do you do....it?
Last Post: 2nd October 2006, 09:15 PM
By ChrisH in forum Scripts
Last Post: 23rd June 2006, 10:59 AM
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)