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
bernie1774Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MarkRRCommented:
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
0
MarkRRCommented:
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
0
bernie1774Author Commented:
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!
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

MarkRRCommented:
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
0
MarkRRCommented:
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
0
bernie1774Author Commented:
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"
0
bernie1774Author Commented:
?? ideas
0
MarkRRCommented:
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
0
MarkRRCommented:
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
0
bernie1774Author Commented:
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
0
MarkRRCommented:
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
0
bernie1774Author Commented:
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.
0
MarkRRCommented:
How about checking the Err object (every time an error occurs in a program it is stored in an Err object that you can reference this error in your code.
(Err.Number will show is the last error that occured)

So why not change the interval in your program to check every 1 minute if the Err.Number = 91.

Somthing like:

Private Sub()
Dim lnInterval = 1 As Integer
On Error Goto ErrorRoutine
lnInterval = 60

Your sub code ...

Your download code...
If Err.Number = 91 Then
    Change download interval to 1 minute
    lnInterval = 1
    Err.Clear
Else
    If lnInterval = 1 Then
        Change download interval back to 1 hour
        lnInterval = 60
     End If
End If

Your sub code (cont.)...

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
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bernie1774Author Commented:
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
0
MarkRRCommented:
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
0
bernie1774Author Commented:
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
0
bernie1774Author Commented:
modulo -- i still have no working answer
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.