Solved

vbscript : How can I handle empty imput in an Inputbox

Posted on 2006-11-28
4
452 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now