Can someone please look over my script below.

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

Re: Input Box quite on blank field. by Tom

Tom
Wed Mar 05 07:23:49 CST 2008

On Mar 5, 7:51 am, RogerDodger Administrator <ro...@mail.com> wrote:
> Can someone please look over my script below.
>
> 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/

Re: Input Box quit on blank field. by Pegasus

Pegasus
Wed Mar 05 07:32:46 CST 2008


"RogerDodger Administrator" <roger@mail.com> wrote in message
news:7d7bba6b18918ca4d3300e768d4@msnews.microsoft.com...
> Can someone please look over my script below.
>
> 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

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.