You need to deal with (at least) three cases – InputBox() returns:
- an empty value (Empty, vbEmpty) because the user pressed Cancel or closed the dialog
- an empty string (“”) or a string of blanks (” “)
- a (hopefully) valid string
In code:
Option Explicit
Do While True
Dim vInp : vInp = InputBox("ee")
WScript.Echo TypeName(vInp)
Select Case True
Case IsEmpty(vInp)
WScript.Echo "Abort"
Exit Do
Case "" = Trim(vInp)
WScript.Echo "Try again"
Case Else
WScript.Echo "Work with " & vInp
Exit Do
End Select
Loop
sample output:
String Try again Empty Abort String Work with aaa
Sorry to say, but the Docs just lie:
If the user clicks OK or presses ENTER, the InputBox function returns
whatever is in the text box. If the user clicks Cancel, the function
returns a zero-length string (“”).
It should be:
… If the user clicks Cancel, the function returns an empty value
(TypeName Empty, VarType vbEmpty).