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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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","defaul t")
if s="" then
exit sub
end if
'
'continue remaining of code....
cheers, dan
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","defaul
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
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
strTemp = InputBox("hi enter some value here","Value?")
if strTemp = "" then 'Cancel is Pressed
msgbox "Empty value"
else
msgbox strTemp
End If