0
votes

I have a VBScript which creates a user form within an Internet Explorer window. This window is created using CreateObject(InternetExplorer.Application). The problem is, if the user closes this window by x'ing out, the window will close, but the script will then throw an error. I want to avoid getting this error. I can't be more specific with regards to the error, as it is different nearly every time. There is a loop in my script, and the error seems to be pointing to whatever line within that loop my script was executing at the time the user closes the program by x'ing out.

I know that one way to do this is to use wscript.CreateObject(InternetExplorer.Application, "IE_") and then use:

Sub IE_onQuit
    wscript.quit
End Sub

Unfortunately, this will not work for me, as the interpreter used by the device I need to run this code on does not recognize the wscript object. In case it matters, my code is being executed through Tecan's EVOware, running on a Windows 7 machine with IE 11. EVOware appears to be bundled with its own interpreter and does not utilize the one built into the Windows OS. No documentation on EVOware's VBscript interpreter appears to exist, at least none that I could find. However, without using the IE_onQuit method I described above, my code will throw the same error when being executed directly via the vbs file using the Windows interpreter, so the error is not something specific to EVOware; it's just that I can't utilize any wscript solutions because of EVOware.

I also tried using On Error Resume Next, but that also doesn't work, because that causes my script to get caught in an infinite loop and never close unless I kill the process in the Task Manager.

Is there any way to achieve my goal (i.e. allow the user to x-out of the window without throwing an error) without the use of wscript? Alternatively, disabling the x-out button would also be an acceptable solution; however, hiding those buttons by making the IE window full screen is not.

Here is an example of my code:

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
2
On Error Resume Next does not work as within the Do Loop in my code above is the line "If sProtocol_Type = "" Or sNumber_of_Plates = "" Or sDispense_Volume = "" Then MsgBox "All fields must be completed! Please enter all values before submitting.", vbCritical" Using On Error Resume Next causes that MsgBox statement to be created infinitely until I end the process.margentieri

2 Answers

1
votes

Could this work then?

if Err.Number<>0 then 
  MsgBox "ERROR: " 
  Exit Do 
End If
0
votes

You can try at the beginning of the script:

On Error Resume Next

and then catch the error codes after the Quit statement, and ignore the one causing it. What is the error, anyway?