12-23-2009, 07:40 PM
Hello All,
I am trying to implement On Error Resume Next in my code but i got error on 2 line
The test run cannot continue due to a syntax error.
Syntax error
Line (1):
can any body please help me out to solve my problem.
My Code:
Thanks
Mahesh
I am trying to implement On Error Resume Next in my code but i got error on 2 line
The test run cannot continue due to a syntax error.
Syntax error
Line (1):
Code:
"On Error GoTo ErrorHandler: ' Enable error-handling routine.".
can any body please help me out to solve my problem.
My Code:
Code:
Public Sub OnErrorDemo()
On Error GoTo ErrorHandler: ' Enable error-handling routine.
Dim x,y,z
x = 32
y = 0
z = x / y ' Creates a divide by zero error
On Error GoTo 0 ' Turn off error trapping.
On Error Resume Next ' Defer error trapping.
z = x / y ' Creates a divide by zero error again
If Err.Number = 6 Then
' Tell user what happened. Then clear the Err object.
Dim Msg As String
Msg = "There was an error attempting to divide by zero!"
MsgBox(Msg, , "Divide by zero error")
Err.Clear() ' Clear Err object fields.
End If
Exit Sub ' Exit to avoid handler.
ErrorHandler: ' Error-handling routine.
Select Case Err.Number ' Evaluate error number.
Case 6 ' Divide by zero error
MsgBox("You attempted to divide by zero!")
' Insert code to handle this error
Case Else
' Insert code to handle other situations here...
End Select
Resume Next ' Resume execution at same line
' that caused the error
End Sub
Thanks
Mahesh