Error handling procedure calls RRS feed

  • Question

  • I have an issue with handling errors in procedure calls in VB6.
    The example code is a project with a single form Form1 and a subroutine Calc with an intentional devide by zero statement as follows:

    Private Sub Form_Load()
    On Error GoTo ErrorHandler
        Call Calc             '1st procedure call without Form1 objectname
        Call Form1.Calc   '2nd procedure call with Form1 objectname
        MsgBox ("Error is handled")
        Resume Next
    End Sub

    Sub Calc()
    Dim vVar As Variant
        vVar = 100 / 0
    End Sub

    When the code is run the 1st procedure call functions as expected: the devide by zero will activate the error handling routine and then resume to the next call.
    The second call references the subroutine including its form objectname Form1.Calc. Then the devide by zero also occurs, but now it generates an runtime error and the program is stopped.
    Why is the second call not activating the error handling routine?

    Tuesday, October 13, 2009 8:30 PM


All replies