Results 1 to 3 of 3

Thread: Triggering an event when an error occurs

  1. #1

    Thread Starter
    Addicted Member Cuallito's Avatar
    Join Date
    Apr 2001
    Location
    You know that chest that you could never get opened? If you ever do, I'm there.
    Posts
    136

    Triggering an event when an error occurs

    How would I fire an event when an error occurs in a class module?
    BTW, Thanks for all your help

    Member of the anti-gay cross-dressing trans-species wolves alliance.

  2. #2
    Fanatic Member Patoooey's Avatar
    Join Date
    Aug 2001
    Location
    New Jersey, USA
    Posts
    774
    This should give you the idea. Create a new project. Add a class mod. Put a commandbutton onto Form1 and add the following code to the class and form.

    VB Code:
    1. ' Class mod code
    2.  
    3. Public Event BadMagic(strError As String)
    4.  
    5. Public Sub Hey()
    6. Dim x As Long
    7.  
    8.     On Error GoTo MyError
    9.    
    10.     ' change this to x = 1 /1 to see that event is only called on error
    11.     x = 1 / 0
    12.    
    13.     MsgBox "Calculation a-ok"
    14.     Exit Sub
    15. MyError:
    16.     RaiseEvent BadMagic("Divide by zero error")
    17. End Sub
    18.  
    19.  
    20. ' form code
    21.  
    22. ' need this to specify that class has events
    23. Private WithEvents c As class1
    24.  
    25. Private Sub c_BadMagic(strError As String)
    26.     ' just popup error msg
    27.    MsgBox strError
    28. End Sub
    29.  
    30. Private Sub Command1_Click()
    31.  
    32.     ' creat new class
    33.     Set c = New class1
    34.    
    35.     ' call class func for processing
    36.     ' if error in this func then c_BadMagic is called
    37.     c.Hey
    38.    
    39. End Sub

  3. #3

    Thread Starter
    Addicted Member Cuallito's Avatar
    Join Date
    Apr 2001
    Location
    You know that chest that you could never get opened? If you ever do, I'm there.
    Posts
    136
    Thanks!
    BTW, Thanks for all your help

    Member of the anti-gay cross-dressing trans-species wolves alliance.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width