PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
Internet Explorer ReadyState returns unexpected error-VBForums
Results 1 to 5 of 5

Thread: Internet Explorer ReadyState returns unexpected error

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    879

    Resolved Internet Explorer ReadyState returns unexpected error

    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function GetTickCount Lib "kernel32" () As Long
    4.  
    5. Public Function GetHTML(URL As String, ByRef HTML As String, Wait As Long) As Boolean
    6.   Dim IE As InternetExplorer    'Browser object
    7.    
    8.   Dim RetryCount As Integer     'Will hold how many times the code was executed
    9.   Dim StartTime As Long         'Will hold how the start time of the timeout lo
    10.  
    11.   Set IE = New InternetExplorer 'Open a new internet explorer
    12.   IE.Visible = False            'Make the browser invisible
    13.  
    14. Retry:
    15.   RetryCount = RetryCount + 1   'Keep count of how many times the code has executed
    16.  
    17.   If RetryCount <= 3 Then
    18.     IE.Navigate URL
    19.   Else
    20.     IE.Quit                     'Close the browser properly
    21.     Set IE = Nothing            'Clear the browser object and free some memory
    22.  
    23.     GetHTML = False
    24.   End If
    25.  
    26.   StartTime = GetTickCount()    'Store the current time for the timeout
    27.  
    28.   [COLOR=Red]While IE.ReadyState <> READYSTATE_COMPLETE[/COLOR]              'Loop until the browser is ready
    29.     If (StartTime + Wait) > GetTickCount Then GoTo Retry  'Exit the loop after a certain amount of time has passed
    30.   Wend
    31.  
    32.   HTML = IE.Document.Body.InnerHTML
    33.  
    34.   IE.Quit                     'Close the browser properly
    35.   Set IE = Nothing            'Clear the browser object and free some memory
    36.  
    37.   GetHTML = True
    38. End Function

    The code in red above returns the error "Object variable or With block variable not set". I don't know why but it shouldn't do that . No if you take out the While Loop, and just put MsgBox IE.ReadyState, it will not raise that error. Can someone tell me why this is happening and what I should do? Thanks for your help
    Last edited by VIP3R; Jul 8th, 2005 at 12:33 PM.
    Visual Basic 6.0
    Visual C++ 5
    Delphi 5


  2. #2
    eltiT resU motsuC Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: Internet Explorer ReadyState returns unexpected error

    if you use:
    Dim WithEvents IE As InternetExplorer

    You will then be able to tap all the Events (IE will appear in your object list in the code window.. and all its events are in the right dropdown)

    But your problem is you are setting IE = nothing and then trying to use it

    you "goto retry" ... if it has done it more than 3 times.. set IE = nothing... etc..
    then tries to use it..
    after your GetHTML = False in the "Retry" section.. you need a Exit Function
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    879

    Re: Internet Explorer ReadyState returns unexpected error

    You're my hero, here's the fixed code. I also realized that I was using ">" rather than "<" in the if statement, which will return true 3 times very fast, and that's why it's going to the RETRY before 3 seconds are up.

    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function GetTickCount Lib "kernel32" () As Long
    4.  
    5. Public Function GetHTML(URL As String, ByRef HTML As String, Wait As Long) As Boolean
    6.   Dim IE As InternetExplorer    'Browser object
    7.    
    8.   Dim RetryCount As Integer     'Will hold how many times the code was executed
    9.   Dim StartTime As Long         'Will hold how the start time of the timeout lo
    10.  
    11.   Set IE = New InternetExplorer 'Open a new internet explorer
    12.   IE.Visible = False            'Make the browser invisible
    13.  
    14. Retry:
    15.   RetryCount = RetryCount + 1   'Keep count of how many times the code has executed
    16.  
    17.   If RetryCount <= 3 Then
    18.     IE.Navigate URL
    19.   Else
    20.     IE.Quit                     'Close the browser properly
    21.     Set IE = Nothing            'Clear the browser object and free some memory
    22.  
    23.     GetHTML = False                'The function has failed
    24.    
    25.     Exit Function
    26.   End If
    27.  
    28.   StartTime = GetTickCount()    'Store the current time for the timeout
    29.  
    30.   While IE.ReadyState <> READYSTATE_COMPLETE
    31.     If (StartTime + Wait) < GetTickCount Then GoTo Retry  'Exit the loop after a certain amount of time has passed
    32.     DoEvents
    33.   Wend
    34.  
    35.   HTML = IE.Document.Body.InnerHTML
    36.  
    37.   IE.Quit                     'Close the browser properly
    38.   Set IE = Nothing            'Clear the browser object and free some memory
    39.  
    40.   GetHTML = True
    41. End Function
    Visual Basic 6.0
    Visual C++ 5
    Delphi 5


  4. #4
    eltiT resU motsuC Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: Internet Explorer ReadyState returns unexpected error

    Glad I could help..

    Check out the WithEvents code... you might like all the goodies you can get into..
    its like adding the webrowser control to you form.. but its really IE on its own.
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    879

    Resolved Re: Internet Explorer ReadyState returns unexpected error

    Oh yeah, I've done things with the WithEvents code, but for this app, I don't need any events to be raised. So leaving it out might save me some valuable memory space :P. Or it might not, but WHO KNOWS!
    Visual Basic 6.0
    Visual C++ 5
    Delphi 5


Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width