Consulting

Results 1 to 7 of 7

Thread: XMLHTTP connection timeout

  1. #1

    XMLHTTP connection timeout

    hi everybody!

    i'm using a xmlhttp object to connect to yahoo server and download historical stock data. everything works fine, but i want to add a connection timeout because sometimes it takes too much time due to the server traffic.

    i'm using this function that i found

    [VBA]
    Private Function RCHGetURLData(pURL As String) As String
    On Error GoTo ErrorExit
    Dim oHTTP As New XMLHTTP
    oHTTP.Open "GET", pURL, False
    oHTTP.Send
    If oHTTP.Status = "200" Then RCHGetURLData = oHTTP.responseText Else GoTo ErrorExit
    Exit Function
    ErrorExit:
    RCHGetURLData = vError
    End Function
    [/VBA]

    i want to set a timeout...how can i do???

    thanks everybody!

  2. #2
    VBAX Tutor Mavyak's Avatar
    Joined
    Jul 2008
    Posts
    204
    Location
    I think you will need IE8-Beta to do that:

    http://msdn.microsoft.com/en-us/library/cc304105(VS.85).aspx

  3. #3
    are you sure?

    i don't know...

    actually i don't use any istance of ie, i just use the xml library...and i don't know if it comes with ie....

    can i do something?

  4. #4
    VBAX Tutor Mavyak's Avatar
    Joined
    Jul 2008
    Posts
    204
    Location
    I'm at a loss. I thought there might be a default property for that in IE but I couldn't find one. I'm not familiar with the XMLHTTP object. I just noticed two asterisks denoting two of its properties and when I checked them both, they were for IE8-Beta. The TimeOut property was one of them.

  5. #5
    hi everybody,

    i wanna ask one more thing

    can i use a timer to use like a timeout, could it work? how can i do?
    i was thinking about something like

    [vba]
    dim start as double
    start = Timer

    while Timer - start < 10 'for example
    ...
    wend
    [/vba]

    i would put the code instead of dots...but it doesn't work...
    thanks,

    i really need this connection timeout!
    Last edited by AntonioZZZ; 09-10-2008 at 02:33 PM.

  6. #6
    Administrator
    2nd VP-Knowledge Base
    VBAX Master malik641's Avatar
    Joined
    Jul 2005
    Location
    Florida baby!
    Posts
    1,533
    Location
    This might work for you:
    [vba]Private Function RCHGetURLData(pURL As String) As String
    On Error GoTo ErrorExit
    Dim oHTTP As New XMLHTTP
    Dim timeOut As Double ' timeout in seconds
    Dim timeOutTime As Double

    timeOut = 60
    timeOutTime = Timer + timeOut

    oHTTP.Open "GET", pURL, False
    oHTTP.Send

    While oHTTP.Status <> "200"
    DoEvents
    If Timer < timeOutTime Then GoTo ErrorExit
    Loop

    RCHGetURLData = oHTTP.responseText
    Exit Function
    ErrorExit:
    RCHGetURLData = vError
    End Function[/vba]




    New to the forum? Check out our Introductions section to get to know some of the members here. Feel free to tell us a little about yourself as well.

  7. #7
    thanks!!!

    i'll try it as soon as i'll be at home...

    i'll let you know

    thanks again!!!

Posting Permissions

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