VBscript InputBox

Author Message
robwm

  • Total Posts : 118
  • Scores: 0
  • Reward points : 0
  • Joined: 3/10/2009
  • Location: Seattle, WA
  • Status: offline
VBscript InputBox Tuesday, November 22, 2011 6:36 AM (permalink)
0
[Helpful answer received] / [List Solutions Only]
Hi,
 
I need to get some input from users that is relevant to my task. If you use the InputBox function, is there any way to detect which button was clicked on? The examples I can find demonstrate testing for a Null response and calling it "Cancel was pressed". The thing is, if you leave the InputBox blank and click OK, then it still qualifies as being cancelled. If a user were to leave the InputBox blank and click OK, I would rather throw a message stating that an entry is required. The user should only be able to click Cancel in order to quit.
 
Some rough code would look something like this:
 
Dim sUserName
sUserName = InputBox("Please enter username:", "Enter UserName")
If sUserName = "" Then
Wscript.Echo "You have cancelled"
End If
 
The IF statement will be be true anytime the InputBox has nothing entered in it regardless of the button that is clicked. I tried vbOK and vbCancel but that must only work with MsgBox.
 
Thanks,
Rob
 
#1
    TNO

    • Total Posts : 2094
    • Scores: 36
    • Reward points : 0
    • Joined: 12/18/2004
    • Location: Earth
    • Status: offline
    Re:VBscript InputBox Tuesday, November 22, 2011 7:07 AM (permalink)
    5
    [This post was marked as helpful]
    http://pastebin.com/SdxH7QCY
    To iterate is human, to recurse divine. -- L. Peter Deutsch
     
    #2
      robwm

      • Total Posts : 118
      • Scores: 0
      • Reward points : 0
      • Joined: 3/10/2009
      • Location: Seattle, WA
      • Status: offline
      Re:VBscript InputBox Tuesday, November 22, 2011 7:33 AM (permalink)
      0
      Out of all of the searching I did, I never came across the TypeName function, especially used the way it is in the example provided. The code below achieves what I was attempting to do.
       
      Dim sUsername
      Do
      sUsername = InputBox("Please enter username:", "Enter UserName") 
      If TypeName(sUsername) = "Empty" Then
      WScript.Quit
      End If
      If Len(Trim(sUsername)) = 0 Then 
      MsgBox "Please Enter Username To Backup",0
      End If
      Loop While Len(Trim(sUsername)) = 0
      WScript.Echo "You entered: " & sUsername 
       
      Thanks for your help!
      Rob
       
      #3

        Online Bookmarks Sharing: Share/Bookmark

        Jump to:

        Current active users

        There are 0 members and 1 guests.

        Icon Legend and Permission

        • New Messages
        • No New Messages
        • Hot Topic w/ New Messages
        • Hot Topic w/o New Messages
        • Locked w/ New Messages
        • Locked w/o New Messages
        • Read Message
        • Post New Thread
        • Reply to message
        • Post New Poll
        • Submit Vote
        • Post reward post
        • Delete my own posts
        • Delete my own threads
        • Rate post

        2000-2012 ASPPlayground.NET Forum Version 3.9