vbscript InputBox ensure Non empty value

824 views Asked by At

How to ensure a non empty string value is entered in InputBox. The control should not go to next statement until this value is entered.

fileName=InputBox("Enter File Name", "File Name")
1

There are 1 answers

0
Tomalak On BEST ANSWER

InputBox returns the string the user has entered when "OK" is pressed, and an "empty" value when "Cancel" is pressed.

Giving the user an option to cancel the program is necessary, so you need to check for that.

Do
    fileName = InputBox("Enter File Name", "File Name")
    If IsEmpty(fileName) Then
        WScript.Quit   ' Cancel has been pressed!
    End If
    fileName = Trim(fileName)
Loop Until fileName > ""

MsgBox "You entered " & filename