按钮消息框,只允许数值

Button Message box, only allowing numerical values

我正在创建一个将 运行 VBScript 作为其一部分的批处理文件,该脚本将打开一个仅包含可单击按钮的 Internet Explorer 消息框,我遇到的问题是我无法输入单击按钮时输出的非数值

它基于此模板https://www.robvanderwoude.com/vbstech_ui_buttons.php#InternetExplorer

当脚本为 运行 时,Internet Explorer 按钮框将出现,当我 select TC01 的按钮时没有任何反应,但当 TC02 的按钮为 selected 和 0322538 当名为 TC03 的按钮被 selected

我需要每个按钮在 selected

时输出一个字符串
' Create an IE object
Set objIE = CreateObject( "InternetExplorer.Application" )
' specify some of the IE window's settings
objIE.Navigate "about:blank"
sTitle="Make your choice " & String( 80, "." ) 'Note: the String( 80,".") is to push "Internet Explorer" string off the window
objIE.Document.title = sTitle
objIE.MenuBar        = False
objIE.ToolBar        = False
objIE.AddressBar     = false
objIE.Resizable      = False
objIE.StatusBar      = False
objIE.Width          = 250
objIE.Height         = 500
' Center the dialog window on the screen
With objIE.Document.parentWindow.screen
    objIE.Left = (.availWidth  - objIE.Width ) \ 2
    objIE.Top  = (.availHeight - objIE.Height) \ 2
End With
' Wait till IE is ready
Do While objIE.Busy
    WScript.Sleep 200
Loop


' Insert the HTML code to prompt for user input
objIE.Document.body.innerHTML = "<div align=""center"">" & vbcrlf _
                              & "<p><input type=""hidden"" id=""OK"" name=""OK"" value=""0"">" _
                              & "<input type=""submit"" value="" TC01 "" onClick=""VBScript:OK.value=EXT1GBMW0151315""></p>" _
                              & "<input type=""submit"" value="" TC02 "" onClick=""VBScript:OK.value=2""></p>" _
                              & "<input type=""submit"" value="" TC03 "" onClick=""VBScript:OK.value=0322538""></p>" _

其余代码与我使用的模板相同

有什么想法吗?

因此更改摘要为:

1:

Dim objIE, sTitle, iErrorNum, myVal 'add myVal declaration

2(使用444作为下面处理的占位开关值):

& "<input type=""submit"" value="" TC01 "" onClick=""VBScript:OK.value=444""></p>" _

3(将 myVal 分配给您想要的输出,将按钮值保存到 retVal,检查它并输出正确的最终值作为 IEButtons 响应):

myVal = "EXT1GBMW0151315"
Dim retVal
retVal = CStr(objIE.Document.all.OK.value)
If retVal = "444" Then
    IEButtons = myVal
Else
    IEButtons = CStr(objIE.Document.all.OK.value)
End If   

最终块工作到 return 你想要的 TC01 值:

 ' Save this code as IEButtonsDemo.vbs
 WScript.Echo IEButtons()

 Function IEButtons()
     ' This function uses Internet Explorer to create a dialog.
     Dim objIE, sTitle, iErrorNum, myVal
    'Create an IE object
    Set objIE = CreateObject( "InternetExplorer.Application" )
    ' specify some of the IE window's settings
    objIE.Navigate "about:blank"
    sTitle="Make your choice " & String( 80, "." ) 'Note: the String( 80,".") is to push "Internet Explorer" string off the window
    objIE.Document.title = sTitle
    objIE.MenuBar        = False
    objIE.ToolBar        = False
    objIE.AddressBar     = false
    objIE.Resizable      = False
    objIE.StatusBar      = False
    objIE.Width          = 250
    objIE.Height         = 500
    ' Center the dialog window on the screen
    With objIE.Document.parentWindow.screen
       objIE.Left = (.availWidth  - objIE.Width ) \ 2
       objIE.Top  = (.availHeight - objIE.Height) \ 2
    End With
    ' Wait till IE is ready
    Do While objIE.Busy
        WScript.Sleep 200
    Loop



    ' Insert the HTML code to prompt for user input
    objIE.Document.body.innerHTML = "<div align=""center"">" & vbcrlf _
                              & "<p><input type=""hidden"" id=""OK"" name=""OK"" value=""0"">" _
                              & "<input type=""submit"" value="" TC01 "" onClick=""VBScript:OK.value=444""></p>" _
                              & "<input type=""submit"" value="" TC02 "" onClick=""VBScript:OK.value=2""></p>" _
                              & "<input type=""submit"" value="" TC03 "" onClick=""VBScript:OK.value=0322538""></p>" _
                              & "<p><input type=""hidden"" id=""Cancel"" name=""Cancel"" value=""0"">" _
                              & "<input type=""submit"" id=""CancelButton"" value=""       Cancel       "" onClick=""VBScript:Cancel.value=-1""></p></div>"

    ' Hide the scrollbars
    objIE.Document.body.style.overflow = "auto"
    ' Make the window visible
    objIE.Visible = True
    ' Set focus on Cancel button
    objIE.Document.all.CancelButton.focus


    'CAVEAT: If user click red X to close IE window instead of click cancel, an error will occur.
    '        Error trapping Is Not doable For some reason
    On Error Resume Next
    Do While objIE.Document.all.OK.value = 0 and objIE.Document.all.Cancel.value = 0
        WScript.Sleep 200
        iErrorNum=Err.Number
        If iErrorNum <> 0 Then    'user clicked red X (or alt-F4) to close IE window
            IEButtons = 0
            objIE.Quit
            Set objIE = Nothing
            Exit Function
        End if
    Loop
    On Error Goto 0

    objIE.Visible = False

    ' Read the user input from the dialog window
    myVal = "EXT1GBMW0151315"
    Dim retVal
    retVal = CStr(objIE.Document.all.OK.value)
    If retVal = "444" Then
        IEButtons = myVal
    Else
        IEButtons = CStr(objIE.Document.all.OK.value)
    End If    
    ' Close and release the object
    objIE.Quit
    Set objIE = Nothing
End Function