Results 1 to 3 of 3

Thread: How do events work ?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2001
    Posts
    118

    How do events work ?

    Hi people...

    Don't laugh.... How do the raise event command works. An easy example will do thanks.

    P.s Not the Err.Raisevent but for example a custom control

    Thanks.

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    You can add events in ActiveX Controls, Class modules and Forms.
    You first have to declare the event:
    Code:
    Public Event MyCustomEvent()
    
    Public Sub SomeMethod()
        RaiseEvent MyCustomEvent
    End Sub
    If the above is declared in a class module or a form you have to use the WithEvents keyword to get the event procedure. If it's in an ActiveX Control this isn't necassary because all events are visible when you add the control to a form.

    Let's say you used the above in a class module (named MyClass), and you want to use that class in a form. Then you could use code simular to this
    Code:
    'a form
    Private WithEvents obj As MyClass
    
    Private Sub Form_Load()
        Set obj = New MyClass
        obj.SomeMethod
    End Sub
    
    Private Sub obj_MyCustomEvent()
         MsgBox "MyCustomEvent was fired!", vbInformation
    End Sub
    Best regards

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2001
    Posts
    118
    thanks man!

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