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
thanks
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
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
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!
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
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
ErrorRoutine:
If Err.Number = 91 Then
Resume
Else
Resume Next
End If
End Sub
ASKER
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"
ASKER
?? 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
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
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
ASKER
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
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
...
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
ASKER
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
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
ASKER
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
ASKER
modulo -- i still have no working answer
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