Sunday, September 11, 2011

internet explorer is ready, is it?


still working in visual studio 2010, vb
with internet explorer interface

i need to know if internet explorer object is ready to receive data

many time in the past my interface was crashing because it was not ready to receive data

i changed the ready management

i used VB events to manage the value of a global (public) variable

it is said that the document download event will trigger everytime a frame load too
that would explain why the downloadbegin and downloadcomplete event does not exist for a frame object
so i will have to identify the frame that triggered the event in the sub (begin and complete)

one for OIE (object internet explorer)
and one for each frame (flef, fmif, fbot)


Public oieready01 As Integer = 1
    Public flefready As Integer = 1
    Public fmidready As Integer = 1
    Public fbotready As Integer = 1

event management after oie was created:

        oIE = New SHDocVw.InternetExplorer
        If logall = 1 Then fil02.WriteLine(DateValue(Now) & " " & TimeValue(Now) & " AddHandler oIE.onQuit, AddressOf oIE_onQuit")
        AddHandler oIE.onQuit, AddressOf oIE_onQuit
        AddHandler oIE.DocumentComplete, AddressOf oIE_onDocumentComplete
        AddHandler oIE.DownloadBegin, AddressOf oIE_onDownloadBegin

event for each frame:

        'AddHandler flef.DownloadBegin, AddressOf oIE_onflefDownloadBegin
        'AddHandler flef.DocumentComplete, AddressOf oIE_onflefComplete

        'AddHandler fmid.DownloadBegin, AddressOf oIE_onfmidDownloadBegin
        'AddHandler fmid.DocumentComplete, AddressOf oIE_onfmidComplete

        'AddHandler fbot.DownloadBegin, AddressOf oIE_onfbotDownloadBegin
        'AddHandler fbot.DocumentComplete, AddressOf oIE_onfbotcomplete

note: that is not working for frames, thus, the comment marks -->  '
apparently, a document object from a frame does not have the downloadbegin property


    '=== OIE internet explorer
    Private Sub oIE_onDownloadBegin()
        If logall = 1 Then fil02.WriteLine(DateValue(Now) & " " & TimeValue(Now) & " oie download begin was called")
        oieready01 = 0
    End Sub
    Private Sub oIE_onflefDownloadBegin()
        If logall = 1 Then fil02.WriteLine(DateValue(Now) & " " & TimeValue(Now) & " flef download begin was called")
        flefready = 0
    End Sub


    Private Sub oIE_onfmidDownloadBegin()
        If logall = 1 Then fil02.WriteLine(DateValue(Now) & " " & TimeValue(Now) & " fmid download begin was called")
        fmidready = 0
    End Sub


    Private Sub oIE_onfbotDownloadBegin()
        If logall = 1 Then fil02.WriteLine(DateValue(Now) & " " & TimeValue(Now) & " fbot download begin was called")
        fbotready = 0
    End Sub
    '=== navigation is completed
    '=== caca
    Private Sub oIE_onDocumentComplete(ByVal pdisp As Object, ByRef url As Object)
        Dim stra As String
        stra = LCase(TypeName(pdisp))
        If stra <> "iwebbrowser2" Then
            If logall = 1 Then fil02.WriteLine(DateValue(Now) & " " & TimeValue(Now) & " type of pdisp: " & stra)


            'stra = pdisp.getattribute("name")
            'MsgBox(stra)
        End If
        oieready01 = 1
    End Sub


    '=== FRAMES
    Private Sub oIE_onflefComplete()
        If logall = 1 Then fil02.WriteLine(DateValue(Now) & " " & TimeValue(Now) & " oie flef complete")
        flefready = 1
    End Sub


    Private Sub oIE_onfmidComplete()
        If logall = 1 Then fil02.WriteLine(DateValue(Now) & " " & TimeValue(Now) & " oie fmid complete")
        fmidready = 1
    End Sub


    Private Sub oIE_onfbotcomplete()
        If logall = 1 Then fil02.WriteLine(DateValue(Now) & " " & TimeValue(Now) & " oie fbot complete")
        fbotready = 1
    End Sub


    Sub oieready()
        Dim maxwai As Integer = 50
        Do
            System.Threading.Thread.Sleep(50)


        Loop Until oieready01 <> 0
        'And flefready <> 0 And fmidready <> 0 And fbotready <> 0
    End Sub

No comments:

Post a Comment