ReadyState WebBrowser Loop.

ugly

New member
Local time
Today, 17:00
Joined
Jan 31, 2009
Messages
6
I have a WebBrowser Object in a form. I check the ReadyState and when the ReadyState has the value 4 I start processing the text content on the loaded webpage.

The problem is that I do not get out of the loop if I do not active a MsgBox. The MsgBox returns 1,2 or 3 the first time the loop i fired. Next time the MsgBox returns 4 and the loop is ended. If I deactivate the MsgBox I get a never ending loop. I have to use CTRL+Breake and vReadyState is 3. Any ideas?

Code:
Private Sub WebBrowser0_Updated(Code As Integer)
    Dim Text As String
    Dim vReadyState 'check if page is fully loaded. 4 = loaded
    vReadyState = 0
    Do Until vReadyState = 4       
      vReadyState = Me!WebBrowser0.ReadyState
      'MsgBox vReadyState
    Loop
       
    
  If vReadyState = 4 Then
    On Error Resume Next
    Text = WebBrowser0.Document.Body.InnerText
    Me.Results = Text
 
If you're trying to determine when a certain page has completed loading, consider something like this...
Code:
Private WithEvents m_wb As SHDocVw.InternetExplorer

Private Sub Form_Open(Cancel As Integer)
   Set m_wb = Me.WebBrowser0.Object
   m_wb.Navigate2 "http://www.yoururl.com"
End Sub

Private Sub m_wb_DocumentComplete(ByVal pDisp As Object, URL As Variant)
   If URL = "http://www.yoururl.com" Then
      'do something here
      'check out pDisp in the locals window
      'it contains an object reference to the page in question
   End If
End Sub
Or maybe your loop hogs resources and the ready state can't be changed. Maybe you need a DoEvents in your loop?
 
You might try:
Code:
[COLOR="Navy"]Do Until[/COLOR] vReadyState = 4
    [B][I]DoEvents[/I][/B]
    vReadyState = Me!WebBrowser0.ReadyState
[COLOR="navy"]Loop[/COLOR]
 
Thanks alot for the help. The DoEvents made the difference. Now it is working.

Problem Solved. :)
 

Users who are viewing this thread

Back
Top Bottom