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)
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
|
|
|
|
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)
To iterate is human, to recurse divine. -- L. Peter Deutsch
|
|
|
|
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)
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
|
|
|
|