CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Threaded View

  1. #1
    Join Date
    Feb 2010
    Posts
    2

    How to know if InternetExplorer control has finished loading a multiframe web page

    Hi All

    I am trying to open a web page using InternetExplorer object in VB6 and I want to set it visible (and extract data from it) only after all its frames are done loading. I have written a function waitFor() to check if the object is still busy. But it is not working well.

    I have included the code below.

    Can any one please give me any idea about how to solve this problem.
    Thanks in Advance.

    Code:
    ' ----------- CODE ----------
    Private Function waitFor(ByRef obj As InternetExplorer, Optional duration As Integer = 15) As Integer
        ' This function should wait for the webpage till it gets loaded or throws error
        ' then it returns the approprate error code
        
        Dim OK, ERROR, TIMEOUT As Integer 
        OK = 1
        ERROR = 2
        TIMEOUT = 3
        
        Dim StartTime As Date
        StartTime = Now
    
        ' Wait for the webpage while it loads completely or some error occures
    label1:
        Do While obj.ReadyState <> READYSTATE_COMPLETE And (Now - StartTime) <= duration
            DoEvents
        Loop
    
        If obj.Busy Then GoTo label1
    
        If (Now - StartTime) >= duration Then ' TIME OUT
            waitFor = TIMEOUT
        ElseIf obj.Document.title = "ERROR: The requested URL could not be retrieved" Then ' ERROR
            waitFor = ERROR
        ElseIf obj.Document.title = "" Then ' ERROR, Other conditions may also be added here
            waitFor = ERROR
        Else
            waitFor = OK
        End If
    End Function
    
    '--------------------
    Private Sub Command1_Click()
    
        Dim obj As New InternetExplorer
        Dim status as Integer
        Dim OK, ERROR, TIMEOUT As Integer 
    
        OK = 1
        ERROR = 2
        TIMEOUT = 3
    
        obj.Navigate2 "http://nseindia.com/"
    
        status = waitFor(obj)
    
        If status = OK Then
            obj.Visible = True
            ' Do something else
        Else
            MsgBox("Error")
        EndIf
    
    End Sub
    
    ' -----------END CODE -----
    Last edited by HanneSThEGreaT; February 17th, 2010 at 08:51 AM. Reason: [CODE] tags!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured