【发布时间】:2016-12-20 20:06:51
【问题描述】:
我有一个在 Internet Explorer 窗口中创建用户表单的 VBScript。此窗口是使用 CreateObject(InternetExplorer.Application) 创建的。问题是,如果用户通过 x'ing out 关闭此窗口,该窗口将关闭,但脚本随后会抛出错误。我想避免出现此错误。关于错误,我不能更具体,因为几乎每次都不同。我的脚本中有一个循环,错误似乎指向了我的脚本在用户通过 x'ing 关闭程序时正在执行的循环中的任何行。
我知道这样做的一种方法是使用 wscript.CreateObject(InternetExplorer.Application, "IE_") 然后使用:
Sub IE_onQuit
wscript.quit
End Sub
不幸的是,这对我不起作用,因为我需要在其上运行此代码的设备所使用的解释器无法识别 wscript 对象。万一这很重要,我的代码是通过 Tecan 的 EVOware 执行的,它在带有 IE 11 的 Windows 7 机器上运行。EVOware 似乎与它自己的解释器捆绑在一起,并且不使用 Windows 操作系统中内置的解释器。似乎没有关于 EVOware 的 VBscript 解释器的文档,至少我找不到。但是,如果不使用我上面描述的 IE_onQuit 方法,我的代码在使用 Windows 解释器直接通过 vbs 文件执行时会抛出相同的错误,因此该错误不是 EVOware 特有的;只是因为 EVOware,我无法使用任何 wscript 解决方案。
我也尝试使用 On Error Resume Next,但这也不起作用,因为这会导致我的脚本陷入无限循环并且永远不会关闭,除非我在任务管理器中终止该进程。
有什么方法可以在不使用 wscript 的情况下实现我的目标(即允许用户在不引发错误的情况下退出窗口)?或者,禁用 x-out 按钮也是一个可接受的解决方案;但是,通过使 IE 窗口全屏来隐藏这些按钮是不行的。
这是我的代码示例:
sHTMLCode = some html code
Set IE = CreateObject("InternetExplorer.Application")
With IE
.ToolBar = False
.StatusBar = False
.Resizable = False
.Height = 500
.Width = 400
.Left = 600
.Top = 200
.Visible = True
CreateObject("WScript.Shell").AppActivate "Internet Explorer"
.Navigate "about:blank"
While .ReadyState <> READYSTATE_COMPLETE
Sleep 0.01
Wend
.document.title = "Title"
.document.body.style.backgroundcolor = "lightgrey"
.document.body.innerHTML = "<center>" & sHTMLCode & "</center>"
Do Until Protocol_Type <> "" And Number_of_Plates <> "" And Dye_Source <> ""
If .document.all.done.value = "clicked" Then
.document.all.done.value = False
.
.
.
stuff
.
.
.
Protocol_Type = sProtocol_Type
Evoware.SetStringVariable "Protocol_Type",Protocol_Type
Number_of_Plates = sNumber_of_Plates
Evoware.SetDoubleVariable "Number_of_Plates",Number_of_Plates
Dye_Source = sDye_Source
Evoware.SetStringVariable "Dye_Source",Dye_Source
Else MsgBox "Please re-enter your protocol parameters.", vbInformation
End If
End If
Loop
.document.all.done.value = True
.Quit
End With
【问题讨论】:
-
On Error Resume Next 不起作用,因为在我上面的代码中的 Do 循环中是“如果 sProtocol_Type = "" Or sNumber_of_Plates = "" Or sDispense_Volume = "" Then MsgBox "All fields must be完全的!请在提交前输入所有值。", vbCritical" Using On Error Resume Next 会导致 MsgBox 语句无限创建,直到我结束进程。
标签: internet-explorer vbscript internet-explorer-11