In the Input box, I have one issue. The user gets an OK and Cancel box.
The Cancel works OK, however if the user leaves a blank field this also
exits via the Wscript.Quit.
I am having great difficulty with this. I'm not sure how to get this working.
If it's blank I am hoping to loop it so the user is asked to enter in a
name again.
Do Until iConfirm = vbYes
Name = InputBox ("Please Enter a Student Username ?", "Name")
If Name = -1 or Name = "" Then
Wscript.Quit
End If
iConfirm = Msgbox("Please Confirm the following Information" &vbCrLf &vbCrLf
& _
"Name: " & Name &vbCrLf &vbCrLf & _
"Select Yes to Continue, No to Change Name Information ",vbYesNo + vbinformation,
_
"Name")
Loop
I believe you need something more like this ...
Do Until iConfirm = vbYes
Do
Name = InputBox ("Please Enter a Student Username ?", "Name")
If IsEmpty(Name) Then Wscript.Quit
Loop until Name <> ""
iConfirm = Msgbox("Please Confirm the following Information" _
& vbCrLf & vbCrLf & "Name: " & Name &vbCrLf &vbCrLf & _
"Select Yes to Continue, No to Change Name Information ",vbYesNo _
& vbinformation, "Name")
Loop
Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/
If Name = -1 or Name = "" Then
Wscript.Quit
This was actually there for the cancel button to quit.
Will the cancel button still do it's job ?
Hello Tom,
The appears to be some confusion here. On the one hand you write
"if the user leaves a blank field this also exits via the Wscript.Quit"
and on the other hand your code says:
If Name = -1 or Name = "" Then Wscript.Quit
In other words, you said one thing and coded the opposite!
There are a few other problems too. You code starts with this line:
Do Until iConfirm = vbYes
This is bad coding: You must not test the value of a variable
unless it has been initiated in some way. Here is a way to avoid this trap:
iConform = vbNo
Do
Name = InputBox ("Please Enter a Student Username ?", "Name")
If Name <> "" Then
iConfirm = MsgBox("Please Confirm the following Information" & VbCrLf &
VbCrLf & "Name: " _
& Name & VbCrLf & VbCrLf & "Select Yes to Continue, No to Change Name
Information ", vbYesNo + vbInformation, "Name")
End If
Loop Until iConform = vbYes
Lastly: You coded
If Name = -1
Now have a look at the InputBox function. It never returns -1; it returns
a string or an "empty" value. Testing it agains -1 makes no sense.
I probably didn't explain carefully what I was trying to do. iConfirm provides
users with an OK and Cancel button option and also an Inputbox for entering
a username (name).
With my original script the CANCEL button would quit out of the script which
was fine. After more testing I realised the OK was causing an issue when
the input field was left blank (and OK selected). When left blank it was
also quiting which it should not have done. Testing proved if the input
name was provided it would run fine and continue with the script.
In summary I still need the CANCEL option to quit out of the script, however
if a blank input was provided with an OK then this should run the loop prompting
the user to supply a name as blanks are invlaid.
Hello Pegasus (MVP),
As Pegasus reported elsewhere, your test for the cancel was flawed. I
fixed it with the change to testing if Name IsEmpty. That is, it will
catch the cancel correctly and loop on no input.
iConform = vbNo
Do
Name = InputBox ("Please Enter a Student Username ?", "Name")
if isempty(name) then WScript.Quit
If Name <> "" Then
iConfirm = MsgBox("Please Confirm the following Information" _
& VbCrLf & VbCrLf & "Name: " _
& Name & VbCrLf & VbCrLf _
& "Select Yes to Continue, No to Change Name Information ", _
vbYesNo + vbInformation, "Name")
End If
Loop Until iConform = vbYes
"RogerDodger Administrator" <ro...@mail.com> wrote in message
news:7d7bba6b18af8...@msnews.microsoft.com...
Do
Name = InputBox ("Please Enter a Student Username ?", "Name")
if isempty(name) then WScript.Quit
Name = Trim(Name) 'remove spaces from ends of name
If Name <> "" Then
Exit Do
else
msgbox "Student Username is required to proceed", vbCritical
end if
Loop
Wscript.Echo "You entered", name