Link to home
Create AccountLog in
.NET Programming

.NET Programming

--

Questions

--

Followers

Top Experts

Avatar of Jeanette Durham
Jeanette Durham🇺🇸

Using IE6, VB.NET, & shdocvw.internetexplorer object. Error occurs when page is closed and trying to load another..
I'm using vb.net, and I'm using the old com library for internet exploer, that is the one you'd use in vb6, or
SHDocVW.InternetExplorer. I have a datagrid that when you click on an item in a column it should load a corresponding web page. The problem is if you close the web page after it opens and then try to open another one it crashes with this error (sadly inside my error handler on the line where I go either 'myexplorer = new shdocvw.internetexplorer' which should just release the handle and give me a new one, or even if I try to do a 'myexplorer =  nothing' first..)

ERROR:
The object invoked has disconnected from its clients. (Exception from HRESULT: 0x80010108 (RPC_E_DISCONNECTED))

The function it occurs inside is here:


    Private Sub openWebPage(ByVal webURL$)
        Dim pageReset As Boolean = False
        On Error GoTo ResetWebPage
        LoadWebPageByUrl(webURL)
        Exit Sub
ResetWebPage:
        If pageReset = False Then
            Err.Clear()
            AttemptToClosePage()
            myExplorer = New SHDocVw.InternetExplorer <= CRASHES ON THIS LINE!
            pageReset = True
            LoadWebPageByUrl(webURL)
            Exit Sub
        End If
    End Sub

Any help on this matter would be greatly appreciated. The whole problem should be as simple as resetting the object that is 'myExplorer' but for some reason that does not work as it would in vb6.

Thanks Experts! ~ Michael

Here is all the related code:

    Private Sub myDataGrid_CurrentCellChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles myDataGrid.CurrentCellChanged
        Dim col As Integer = Me.myDataGrid.CurrentCell.ColumnNumber
        Dim row As Integer = Me.myDataGrid.CurrentCell.RowNumber
        'On Error GoTo Whatever
        Dim cellVal$ = nz(Me.myDataGrid.Item(row, col))
        If Me.myDataGrid.TableStyles().Count = 0 Then Exit Sub
        Dim colName$ = Me.myDataGrid.TableStyles(0).GridColumnStyles.Item(col).MappingName
        'Dim colName$ = myDB.myDS.Tables(gTableLoadedInGrid).Columns(col).ColumnName
        'MsgBox(row & vbCrLf & col)
        If Not colName = "RecNum" Then Exit Sub
        If cellVal <> "" Then
            Dim newurl = makeUrl(cellVal)
            If newurl <> "" Then openWebPage(newurl)
        End If
Whatever:
    End Sub

Private Sub openWebPage(ByVal webURL$)
        Dim pageReset As Boolean = False
        On Error GoTo ResetWebPage
        LoadWebPageByUrl(webURL)
        Exit Sub
ResetWebPage:
        If pageReset = False Then
            Err.Clear()
            AttemptToClosePage()
            myExplorer = New SHDocVw.InternetExplorer <= CRASHES ON THIS LINE!
            pageReset = True
            LoadWebPageByUrl(webURL)
            Exit Sub
        End If
    End Sub

    Private Function makeUrl(ByVal recNum$) As String
        Dim suffix$ = ""
        If InStr("ABCDEFGHIJKLMNOPQRSTUVWXYZ", UCase(Mid(recNum, Len(recNum), 1))) > 0 Then
            suffix = recNum(Len(recNum))    'we have a letter
            recNum = Mid(recNum, 1, Len(recNum) - 1)
        End If
        makeUrl = "about:blank"
        makeUrl = Replace(Replace(gRecorderURL, "[RecNum]", recNum), "[Suffix]", suffix)
    End Function

    Private Sub LoadWebPageByUrl(ByVal webUrl$)
        Me.fldDoing.Text = "Opening Web Page.."
        With myExplorer
            .Navigate(webUrl)
            waitForDoc(myExplorer)
            'set the PDF option checkbox to false & submit form to go to file
            .Document.Forms("frmMain")("format")(0).Click()
            .Document.Forms("frmMain")("PageNo").value = 1
            .Document.Forms("frmMain")("btnAllPages").Click()   'SUBMIT form
            .Visible = True
        End With
        Me.fldDoing.Text = ""
        'Try to figure out here how to set the focus of this window
    End Sub

    Private Sub AttemptToClosePage()
        On Error GoTo JustLeaveSub
        myExplorer.Quit()
        myExplorer.Visible = False
JustLeaveSub:
    End Sub

Zero AI Policy

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


ASKER CERTIFIED SOLUTION
Avatar of Bob LearnedBob Learned🇺🇸

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Create Account

Avatar of Jeanette DurhamJeanette Durham🇺🇸

ASKER

Yeah what it needs to do essentially is actually manipulate the web page. It needs to not only load the internetexplorer, but fill in these objects on the form (after the web page is done loading)..

 .Document.Forms("frmMain")("format")(0).Click()
            .Document.Forms("frmMain")("PageNo").value = 1
            .Document.Forms("frmMain")("btnAllPages").Click()   'SUBMIT form

which then finally loads the right page. It doesn't actually go directly to the page. So I'm willing to try the above code, The Learned One, but I'm anticapating already it won't actually help me..

Avatar of Jeanette DurhamJeanette Durham🇺🇸

ASKER

Basically I don't know how to use the new .net library (for internet) so I've just been using the old one. What really baffles me is how .net is refusing to unload the object 'myExplorer' (shdocvw.internetexplorer) and assign it to a new one. If I could do that, all the rest of my code would work as is, and there'd be no need to rewrite it.

Avatar of Bob LearnedBob Learned🇺🇸

Do you have 2005?

Bob

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


Avatar of Jeanette DurhamJeanette Durham🇺🇸

ASKER

Yeah, your code totally worked however, to open a page.. and now I kinda see how to get alist of processes and things and that's actually really neat. But yeah, I don't know how to get a handle to the iexplore.exe object now and reach the .document property.. (I'm also uncertain if people use my program and they've got ie7 and I've got ie6 if it'll still work. I've been edgy about all the internet stuff ever since the ie7 came out and all these other programs I'd written for work stopped working..)
~Michael

Avatar of Jeanette DurhamJeanette Durham🇺🇸

ASKER

For the IE Explorer I'm using:
Version: 6.0.2900.2180.xpsp_sp2_gdr.060301-1519C0

Avatar of Bob LearnedBob Learned🇺🇸

2005 has the WebBrowser control, and you can get all that you need that way.

Bob

Free T-shirt

Get a FREE t-shirt when you ask your first question.

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of Jeanette DurhamJeanette Durham🇺🇸

ASKER

Oh, ok, you're talking about the vb.net 2005 version (Yes that is what I have..)
So you're saying the old com library can't be made to work? I thought that was something you could do in .net, is use the older com libraries?
~Michael

(Yeah my friend has some experience using the new one and he says that overall in .net microsoft made no great improvements or any new things to the webbrowser object, and in fact actually made it /more/ difficult to use...)

Avatar of Jeanette DurhamJeanette Durham🇺🇸

ASKER

Oh yeah, this is how I'm defining my object 'myexplorer'. It's global. Could the WithEvents be part of the issue?

Public WithEvents myExplorer As New SHDocVw.InternetExplorer

Avatar of Bob LearnedBob Learned🇺🇸

No, it sounds more like a COM disconnect problem.

Bob

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


Avatar of Jeanette DurhamJeanette Durham🇺🇸

ASKER

I got it to work!

The key was to encapsulate it with a try/except block instead of using the on error goto, which the documentation claimed worked the same way, even tho it's vb6, but ha, I've found proof that it doesn't handle them the same. Anyways, thanks for your help The Learned One. I'm going to take your first answer because technically it would circumvent the problem and could've been a possible solution, if I wasn't so picky. As well as using the new webbrowser, that was good too.. I just don't feel like the effort today.. :)

Here is the working code:

    Public Sub openWebPage(ByVal webURL$)
        Dim pageReset As Boolean = False
        Try
            LoadWebPageByUrl(webURL)
        Catch ex As Exception
            Err.Clear()
            AttemptToClosePage()
            ' myExplorer = Nothing
            myExplorer = New SHDocVw.InternetExplorer
            pageReset = True
            LoadWebPageByUrl(webURL)
        End Try
    End Sub

    Public Sub LoadWebPageByUrl(ByVal webUrl$)
        Main.fldDoing.Text = "Opening Web Page.."
        With myExplorer
            .Navigate(webUrl)
            waitForDoc(myExplorer)
            'set the PDF option checkbox to false & submit form to go to file
            .Document.Forms("frmMain")("format")(0).Click()
            .Document.Forms("frmMain")("PageNo").value = 1
            .Document.Forms("frmMain")("btnAllPages").Click()   'SUBMIT form
            .Visible = True
        End With
        Main.fldDoing.Text = ""
        'Try to figure out here how to set the focus of this window
    End Sub
.NET Programming

.NET Programming

--

Questions

--

Followers

Top Experts

The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.