?
Solved

MS internet control error handling

Posted on 2004-11-15
20
Medium Priority
?
175 Views
Last Modified: 2010-05-02
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
0
Comment
Question by:bernie1774
  • 9
  • 8
17 Comments
 
LVL 2

Expert Comment

by:MarkRR
ID: 12590814
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
 
LVL 2

Expert Comment

by:MarkRR
ID: 12590822
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
 

Author Comment

by:bernie1774
ID: 12590834
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 2

Expert Comment

by:MarkRR
ID: 12590843
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
 
LVL 2

Expert Comment

by:MarkRR
ID: 12590878
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
 

Author Comment

by:bernie1774
ID: 12590933
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
 

Author Comment

by:bernie1774
ID: 12600716
?? ideas
0
 
LVL 2

Expert Comment

by:MarkRR
ID: 12600822
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
 
LVL 2

Expert Comment

by:MarkRR
ID: 12600926
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
 

Author Comment

by:bernie1774
ID: 12601066
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
 
LVL 2

Expert Comment

by:MarkRR
ID: 12604314
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
 

Author Comment

by:bernie1774
ID: 12605745
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
 
LVL 2

Accepted Solution

by:
MarkRR earned 600 total points
ID: 12606303
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
 

Author Comment

by:bernie1774
ID: 12608613
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
 
LVL 2

Expert Comment

by:MarkRR
ID: 12613341
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
 

Author Comment

by:bernie1774
ID: 12671820
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
 

Author Comment

by:bernie1774
ID: 12908568
modulo -- i still have no working answer
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

831 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