cancel array Input Box

允我心安 提交于 2019-12-20 07:36:40

问题


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.


回答1:


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)


来源:https://stackoverflow.com/questions/37363976/cancel-array-input-box

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!