I am trying to make the cancel function work for my array it works for a simple input box but Array(InputBox( does not like it very much.
Working code.
If strVarValue = vbNullString Then MsgBox ("User canceled!") WScript.Quit End If
What I need help with
strIPAddress = Array(InputBox("IP address")) If strIPAddress = vbNullString Then MsgBox ("User canceled!") WScript.Quit End If
Doesn't like the Array hence why I'm getting type mismatch.
Do the conversion only if the user did not press "Cancel":
userInput = InputBox("IP address") If userInput = "" Then MsgBox ("User canceled!") WScript.Quit End If strIPAddress = Array(userInput)
Also, if you want to distinguish between "user pressed Cancel" and "user pressed OK without entering a value" you need to check if the variable is Empty
:
userInput = InputBox("IP address") If IsEmpty(userInput) Then MsgBox ("User canceled!") WScript.Quit ElseIf userInput = "" Then MsgBox ("Missing input!") WScript.Quit 1 End If strIPAddress = Array(userInput)