|
-
Aug 26th, 2000, 10:24 PM
#1
Thread Starter
Frenzied Member
Okay, I know this is probably a dumb question but can someone explain what 'On Error Resume Next' means?
Does that just mean that the code will keep running even though there was an error or does it mean something else?
Say I have the following code:
Code:
If Err Then
'-- Exit function
MsgBox "There was an error!"
Exit Funtion
End If
If I had declared "On Error Resume Next", would that mean that it would just go to the next line (End If) and stop or would it continue with the remaining code in that function?
Thanks,
Dan
-
Aug 26th, 2000, 10:40 PM
#2
On Error Resume Next Makes it so, if your Sub has an error, it ignores it.
-
Aug 26th, 2000, 10:43 PM
#3
When you use On Error Resume Next, it'll just keep going as though nothing had happened, but you can tell when an error had occurred with Err.Number
Code:
On Error Resume Next
Open "C:\autoexec.bat" For Input As #1
If Err.Number = 53 Then
MsgBox "File Not Found!"
Err.Clear
End If
Hope it helps
Sunny
-
Aug 27th, 2000, 10:09 AM
#4
Hyperactive Member
I think that it is better to use it like that:
Err.Clear
On Error Resume Next
Open "C:\autoexec34.bat" For Input As #1
If Err.Number <> 0 Then
MsgBox Err.Description
Err.Clear
End If
this way, you will know of any error that happen and not just if a specific one accured.
In the beginning the universe was created. This has made a lot of people very angry and is generally regarded as a bad idea.
- Douglas Adams
The Hitchhiker's Guide to the Galaxy
-
Aug 27th, 2000, 10:30 AM
#5
Yes just as the above posts has stated the On Error Resume Next statement just goes on to the next line if an error is raised. But this could make some unexpected results.
Consider this code:
Code:
Public Sub AnExample()
Dim sngDivider As Single
On Error Resume Next
sngDivider = Val(Text1.Text)
If 10 / sngDivider = 2 Then
MsgBox "The Result Is 2"
Else
MsgBox "The Result Is Not 2"
End If
End Sub
This would of course popup a message that stated that the result is two if the user has typed in 5 in the Text1 textbox, right.
Well consider that the user has typed in 0 (zero) or a non numeric text. Then the if statement would raise an error, you can't divide by zero.
But since we got an On Error Resume Next statement it would just go on with the next line and popup the MsgBox that stated that the result is 2.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|