Link to home
Start Free TrialLog in
Avatar of itbabe
itbabe

asked on

vbscript : How can I handle empty imput in an Inputbox

Eg.  I want to quit a script when a user did not provide string input in an inputbox.
ASKER CERTIFIED SOLUTION
Avatar of TimCottee
TimCottee
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pradapkumar
pradapkumar

dim strTemp as String
strTemp = InputBox("hi enter some value here","Value?")
if strTemp = "" then    'Cancel is Pressed
    msgbox "Empty value"
else
    msgbox strTemp
End If
Avatar of Dany Balian
both above solutions are correct..
but i would recommend to add an exit sub so that the remaining of code does not run.

din s as string
s=inputbox("title","default")
if s="" then
 exit sub
end if
'
'continue remaining of code....

cheers, dan
Though all of the above are correct, if it is vb script they would need slight modifications. Using Tim's as a basis:

Dim InputValue
InputValue = InputBox("Enter something")
If Len(InputValue) = 0 Then
    Msgbox "You didn't enter a value, quitting"
    WScript.Quit
End If

You could consider using    If len(trim(inputvalue)) = 0 then     as well, in case the user tries to get around your checking by putting a space or something in there
Matt