Link to home
Start Free TrialLog in
Avatar of bernie1774
bernie1774

asked on

MS internet control error handling

Right now i've got an application that is using the MS inet control to go out and download a web page once an hour, the problem that arrises is that if the computer its running on looses its internet connection, when the program goes to connect to the site it dies with a run time error '91'.  Is there anyway to make the program interperit this error and make it just go into a wait state and keep retrying until it gets a connection back?

thanks
Avatar of MarkRR
MarkRR
Flag of United Kingdom of Great Britain and Northern Ireland image

On Error Goto ErrorRoutine
On Error Goto 0

...

ErrorRoutine:
   If Err.Number = 91 then
      If MsgBox "Internet Connection Down.  Try Again.", vbInformation+vbYesNo) = vbYes
          Resume
      Else
          Resume Next
      Endif
   Endif
Sorry about that should read:

On Error Goto ErrorRoutine

...

On Error Goto 0

ErrorRoutine:
   If Err.Number = 91 then
      If MsgBox "Internet Connection Down.  Try Again.", vbInformation+vbYesNo) = vbYes
          Resume
      Else
          Resume Next
      Endif
   Endif
Avatar of bernie1774
bernie1774

ASKER

that would prompt the user for input, is there a way to just have it wait a few seconds and retry until it gets a connection back?  This application is made to run more or less unattended so depending on a person pressign yes or no wouldnt really work.

thanks!
3rd time lucky.

Private Sub [YourSub]()
On Error GoTo ErrorRoutine

[Your Code...]

On Error GoTo 0

ErrorRoutine:
   If Err.Number = 91 Then
      If MsgBox("Internet Connection Down.  Try Again.", vbInformation + vbYesNo) = vbYes Then
          Resume
      Else
          Resume Next
      End If
   End If
End Sub
This error routine should keep attempting the download.  You may need abreak in there if the connection to the internet is perminantly disconnected.

ErrorRoutine:
   If Err.Number = 91 Then
      Resume
   Else
      Resume Next
   End If
End Sub
stupid question, but how do i implement the above, obviously i put the goto statements in my program code right after my variable definitions, but what do i need to do to create the ErrorRoutine, i treid putting it in a SUB but i still got an error saying cant find label "ErrorRoutine"
?? ideas
Private Sub ()
On Error Goto ErrorRoutine

...



Your code goes here



...

On Error GoTo 0
Exit Sub

ErrorRoutine:
   If Err.Number = 91 Then
      If MsgBox("Internet Connection Down.  Try Again.", vbInformation + vbYesNo) = vbYes Then
          Resume
      Else
          Resume Next
      End If
   End If

End Sub
Ignore last post.

The error routine needs to be in the same sub routine as the on error command,  usually at the bottom.  Use an Exit Sub command just above the error routine to force the system to skip the routine,  otherwise the system will execute the routine before it reaches the End Sub command.

i.e
Private Sub()
On Error Goto ErrorRoutine

...



Your sub code goes here


...

On Error GoTo 0
Exit Sub

ErrorRoutine:
   If Err.Number = 91 Then
      Resume
   Else
      Resume Next
   End If
End Sub
ok now its not giving me the run time error anymore 1 down lol

BUT

when there is no lan connection and the program goes to look for an update it just hangs there unresponsive (at 50% cup usage on a P4 2.4 lol), ever after the connection is restored with the following code:

ErrorRoutine:
   If Err.Number = 91 Then
      Resume
   Else
      Resume Next
   End If
End Sub
Try,  this routine the system will skip the download if no connection.

...

On Error GoTo 0
Err.Clear
Exit Sub

ErrorRoutine:
   If Err.Number = 91 Then
      Resume Next
   Else
      MsgBox "An Error Occurred: "+Err.Description, vbInformation)
   End If
End Sub
i hate to keep shooting ideas down here, but the prog cant really just skip its download and wait an hour (by that time 2 hours since the last update) to get its info.  

the retry one was exactly what i'm looking for but what would it take to get that working?  A counter somewhere between retries or something maybe?  I dont get why its hanging on that one.
ASKER CERTIFIED SOLUTION
Avatar of MarkRR
MarkRR
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
only problem with that is right now the program downloads the pages at certain minutes of the hour :05 past and :59 past every hour, so theres no real easy way to implement that code...why does that first example of just constantly retrying lock the dam thing up i wonder, that would be the easiest solution for all this
Yep sure would,

I think what you suggested earier about of putting in a few seconds delay may do the trick.

That will involve declaring the sleep function in the windows kernel.

To do this paste the following code into the module level above all of your sub routines.

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Then simply call the function sleep with a delay of milliseconds:

Sleep 1000
OK, finally got around to tryign the sleep function and still the same thing -- as soon as it fails to connect the program locks up (not responding in task manager) ...dunno what gives
modulo -- i still have no working answer