+ Post New Thread
Results 1 to 4 of 4
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". ...
  1. #1

    Join Date
    Apr 2013
    Posts
    4
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    VBS script question

    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.
    "
    Last edited by bill23077; 22nd April 2013 at 05:48 PM.

  2. #2
    TechSupp's Avatar
    Join Date
    Mar 2007
    Location
    South Yorkshire
    Posts
    1,875
    Thank Post
    295
    Thanked 120 Times in 101 Posts
    Rep Power
    40
    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!

  3. #3

    Join Date
    Apr 2013
    Posts
    4
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Quote Originally Posted by TechSupp View Post
    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!


    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 07:47 PM.

  4. #4

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,680
    Thank Post
    3,210
    Thanked 1,030 Times in 955 Posts
    Rep Power
    361
    Linky -> http://www.vbforums.com/showthread.p...-Whole-Numbers

    Dim Numeric

    Numeric = InputBox("Please enter a whole number!")

    if Numeric=int(Numeric) then
    'whole
    MsgBox "A whole number was entered"
    Else
    MsgBox "Please enter a whole number"
    End If

SHARE:
+ Post New Thread

Similar Threads

  1. VB Script to create folders
    By markesmith in forum Scripts
    Replies: 2
    Last Post: 26th April 2007, 03:03 PM
  2. VB script template
    By ajbritton in forum Coding
    Replies: 6
    Last Post: 27th December 2006, 09:16 PM
  3. Replies: 4
    Last Post: 25th December 2006, 09:15 PM
  4. VB Script ti check for folder and then copy contents to PC
    By tosca925 in forum How do you do....it?
    Replies: 4
    Last Post: 2nd October 2006, 08:15 PM
  5. VBS script for prestaging computers anyone?
    By ChrisH in forum Scripts
    Replies: 7
    Last Post: 23rd June 2006, 09:59 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •