Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Input Box quite on blank field.

756 views
Skip to first unread message

RogerDodger Administrator

unread,
Mar 5, 2008, 7:51:45 AM3/5/08
to
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


Tom Lavedas

unread,
Mar 5, 2008, 8:23:49 AM3/5/08
to

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/

RogerDodger Administrator

unread,
Mar 5, 2008, 8:32:45 AM3/5/08
to
I noticed your removed:

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,

Pegasus (MVP)

unread,
Mar 5, 2008, 8:32:46 AM3/5/08
to

"RogerDodger Administrator" <ro...@mail.com> wrote in message
news:7d7bba6b18918...@msnews.microsoft.com...

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.


RogerDodger Administrator

unread,
Mar 5, 2008, 9:03:26 AM3/5/08
to
I am new to this and am not surprised there are signs of bad coding. I can
admit that and thank you for all your help.

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),

Tom Lavedas

unread,
Mar 5, 2008, 11:17:42 AM3/5/08
to

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.

Pegasus (MVP)

unread,
Mar 5, 2008, 11:39:42 AM3/5/08
to
If you want the program to terminate on Cancel then you
must check the response from InputBox for an "empty"
string (which is NOT the same as a "blank" string!). Here
is how it's done:

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...

Todd Vargo

unread,
Mar 5, 2008, 5:31:13 PM3/5/08
to
RogerDodger Administrator wrote:
> 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.

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

0 new messages