set timeout value on CreateObject("InternetExplorer.Application")

Posted on 2004-11-12
Last Modified: 2008-01-09
sample code:

Set myIE = CreateObject("InternetExplorer.Application")
myIE.navigate ""

Do Until myIE.Busy = False

How can i set the timeout value for the http request?

Question by:Flash5
    LVL 6

    Accepted Solution

    the easy way is to use the timer control
    dim bTimeOut as boolean

    bTimeOut = False
    Do Until myIE.Busy = False or bTimeOut

    Private Sub Timer1_Timer()
    bTimeOut = true
    end sub

    the hard way would be to use the timer api functions
    LVL 11

    Assisted Solution


     - create a timer control and a command button
     - paste this code:
    Dim myIE As Object
    Dim ElapsedTime As Integer

    Private Sub Form_Load()
        Timer1.Enabled = False
    End Sub

    Private Sub Form_Unload(Cancel As Integer)
        Set myIE = Nothing
    End Sub

    Private Sub Command1_Click()
        Set myIE = CreateObject("InternetExplorer.Application")
        myIE.Visible = True
        myIE.navigate ""

        ElapsedTime = 0
        Timer1.Interval = 1000
        Timer1.Enabled = True
    End Sub

    Private Sub Timer1_Timer()
        If myIE.busy = False Then
            MsgBox "Done!"
            ElapsedTime = ElapsedTime + 1
            If ElapsedTime = 10 Then
                MsgBox "Time-out!"
                Timer1.Enabled = False
            End If
        End If
    End Sub
    LVL 32

    Expert Comment

    You can use DateDiff to compare 2 times, in this case we can see when the request has exceeded our time limit.

    Dim lSeconds As Long
    Dim dtStart As Date

    'Set a 3 second timeout
    lSeconds = 3
    'Get the time before navigating
    dtStart = Now
    myIE.Navigate2 ""

    'Check the time against the start time
    Do While (myIE.ReadyState <> READYSTATE_COMPLETE)
        If (DateDiff("s", dtStart, Now) > lSeconds) Then
            Debug.Print "Time Out"
            Exit Do
        End If
    LVL 17

    Expert Comment

    >>How can i set the timeout value for the http request?
    IE has it's own time-out so to avoid conflicts with it, you may want to change IE's time-out instead.;en-us;181050

    If you don't think your custom time-out will exceed IE's, the above suggestions would be better.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
    You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now