Solved

vbscript : How can I handle empty imput in an Inputbox

Posted on 2006-11-28
4
458 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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.
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month7 days, 14 hours left to enroll

632 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