Solved

vbscript : How can I handle empty imput in an Inputbox

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
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…

863 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

16 Experts available now in Live!

Get 1:1 Help Now