[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1402
  • Last Modified:

inet Error Trapping

I cannot trap errors with the inet function. I have tried using on error goto without an success.

I have even tried checking for icResponse=icError and even that can trap it. The error I am forcing is a time-out event.

Any pointers to what could be wrong would be very helpful.

Mike
0
mikem
Asked:
mikem
  • 8
  • 6
1 Solution
 
Erick37Commented:
If the RequestTimeout property is nonzero, then if you make a request using the Execute method, then the error will be caught in the StateChanged event.

Code from VB Help:

'Use the StateChanged event to receive notification of an error, as shown below:
Private Sub Inet1_StateChanged(ByVal State As Integer)
    Dim strMess As String ' Message variable.
    Select Case State
    ' ... Other cases not shown.
    Case icError  ' 11
        ' Get the Text of the error.
        strMess = "ErrorCode: " & Inet1.ResponseCode & _
        " : " & Inet1.ResponseInfo
    End Select

    Debug.Print strMess
End Sub
0
 
mikemAuthor Commented:
Thanks for the above, however I am using 'getchunk' I have tried similar response trapping, but I guess I am way off on a tangent with this one..

Mike
0
 
mikemAuthor Commented:
Adjusted points to 75
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
mikemAuthor Commented:
I have raised the points to try and find a solution. If there is none, then I will have to resort to a third party app.

For info, VB6 Enterpise, SR3

I am trying (successfully!) to force a time-out event from the client machine in connecting to the server. I have set the Inet1.RequestTimeOut=5 (Seconds) to force the error.

On Error does not trap this, nor does checking the State=11 within the StateChanged Event

The program reports the error (Time-Out) but this is not trapped or detected in State

Help!

Mike



0
 
Erick37Commented:
If you open the connection using .OpenURL, then a runtime error will be generated on a timeout, and it will not be passed to StateChanged.

Use an On Error GoTo ... statement to catch the error.
0
 
mikemAuthor Commented:
Thanks Erick37, but ...

I have tried that, but it does not trap the error.

I have tried placing the On Error Goto at the beging of the code, just before the openUrl and within the StateChanged Event..

This is really frustrating as I dont want to release loose code...

Mike
0
 
Erick37Commented:
What is the error that is raised?
Could you post a portion of your code?
0
 
mikemAuthor Commented:
' Relevant Portion of Code

Private Sub Command1_Click()

Dim strURL As String
Dim strData As String
On Error Goto errInetErrors
Inet1.RequestTimeOut=5 ' To force the error during test

Inet1.URL = strURL
strData = Inet1.OpenURL(strURL, icString) 'Error occurs here

' rest of code here

 Error Message Received: 35761, Request Timed Out.
 This matches the documented error in the Help File ..
 Trappable Errors - In Internet Transfer Control - IcTimeout

Mike
0
 
Erick37Commented:
This works for me. It catches the timeout.

Option Explicit
Private Sub Command1_Click()
    Dim strURL As String
    Dim strData As String
    strURL = "http://www.experts-exchange.com"
    Inet1.RequestTimeout = 1 ' To force the error during test
    On Error GoTo INETERR
    Inet1.URL = strURL
    strData = Inet1.OpenURL(strURL, icString) 'Timeout is caught
    Wait 'Always wait before executing another Inet request
    Text1.Text = strData
    Exit Sub
INETERR:
    MsgBox "Error " & Err.Number & ": " & Err.Description
    Err.Clear
    Exit Sub
End Sub

Private Sub Inet1_StateChanged(ByVal State As Integer)
    Select Case State
    Case icNone
        Debug.Print "0   No state to report."
    Case icResolvingHost
        Debug.Print "1 Looking up the IP address of the specified host computer."
    Case icHostResolved
        Debug.Print "2 Successfully found the IP address of the specified host computer."
    Case icConnecting
        Debug.Print "3 Connecting to the host computer."
    Case icConnected
        Debug.Print "4 Successfully connected to the host computer."
    Case icRequesting
        Debug.Print "5 Sending a request to the host computer."
    Case icRequestSent
        Debug.Print "6 Successfully sent the request."
    Case icReceivingResponse
        Debug.Print "7 Receiving a response from the host computer."
    Case icResponseReceived
        Debug.Print "8 Successfully received a response from the host computer."
    Case icDisconnecting
        Debug.Print "9 Disconnecting from the host computer."
    Case icDisconnected
        Debug.Print "10 Successfully disconnected from the host computer."
    Case icError
        Debug.Print "11 ErrorCode: " & Inet1.ResponseCode & _
            " : " & Inet1.ResponseInfo
    Case icResponseCompleted
        Debug.Print "12 Response Completed"
    End Select
End Sub

Private Sub Wait()
    Do
        DoEvents
    Loop Until Not Inet1.StillExecuting
    Debug.Print "Done executing request"
End Sub
0
 
mikemAuthor Commented:
' Relevant Portion of Code

Private Sub Command1_Click()

Dim strURL As String
Dim strData As String
On Error Goto errInetErrors
Inet1.RequestTimeOut=5 ' To force the error during test

Inet1.URL = strURL
strData = Inet1.OpenURL(strURL, icString) 'Error occurs here

' rest of code here

 Error Message Received: 35761, Request Timed Out.
 This matches the documented error in the Help File ..
 Trappable Errors - In Internet Transfer Control - IcTimeout

Mike
0
 
mikemAuthor Commented:
Erick,

Thank you for your help on this, but I tried that even in a new project, and it still bombs out.

Could we compare MSINET.OCX

My Version: 6.00.8169
Size: 115,016 Bytes

I have installed SR2 and SR3

Mike
0
 
Erick37Commented:
Check your settings in Tools->Options->General.
Make sure that "Break on all errors" is NOT selected.
If it is, then the error handler not catch the error.

I am using VB5, but I think the RequestTimeout error is trappable.
0
 
mikemAuthor Commented:
Erick,

Arghhhh!!!

I knew it was something daft that I had done.

I set that to break on all errors a few weeks back to turn off error handling during another coding project. Then obviously, forgot all about it.

Thank you for your time (and patience) on this problem.

Best regards,

Mike
0
 
Erick37Commented:
Glad to help.
I should have thought of that sooner.
:-)
0

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

  • 8
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now