Solved

vbscript : How can I handle empty imput in an Inputbox

Posted on 2006-11-28
4
455 Views
Last Modified: 2008-01-09
Eg.  I want to quit a script when a user did not provide string input in an inputbox.
0
Comment
Question by:itbabe
4 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 500 total points
ID: 18026888
Hi itbabe,

Dim InputValue As String
InputValue = InputBox(......)
If Len(InputValue) = 0 Then
    Msgbox "You didn't enter a value, quitting"
Else
    'your code here
End If

Tim Cottee
0
 
LVL 9

Expert Comment

by:pradapkumar
ID: 18026901
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
0
 
LVL 11

Expert Comment

by:Dany Balian
ID: 18027120
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
0
 
LVL 35

Expert Comment

by:mvidas
ID: 18027703
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
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question