How to raise an event from vb6 module?

I developed my own visual basic control 6 and announced some custom events. Is it possible in vb6 to raise these events from a module or do I need to implement special "proxy" methods in my control to do this?

+3
source share
2 answers

RaiseEvent:

Compilation error:
Valid only in the object module.

(which makes sense.)

Yes, you need a method Friendfor your class that you call to raise events from your module:

Grade:

Public Event Click()

Friend Sub OnClick()
  RaiseEvent Click
End Sub

Module:

someVar.OnClick
+7
source

Perhaps the answer you are looking for isn't completely, but you can use Event-like procedures from simple modules:

: IEventsClient (Class Module):

Option Explicit

Public Sub PropertyChanged(sender As Object, property As String)
End Sub

MyModule:

Option Explicit

Public EventClients As Collection

Public Sub OnPropertyChanged(property As String)
    Dim eventsClient As IEventsClient
    Dim element As Variant

    For Each element In EventClients
        Set eventsClient = element
        eventsClient.PropertyChanged MyControl, property
    Next

End Sub

Public Sub RaiseSomePropertyChanged()
    OnPropertyChanged "SomeProperty"
End Sub

:

Option Explicit
Implements IEventsClient

Private Sub Form_Load()
    'Entry point of the application'
    Set MyModule.EventClients = New Collection
    MyModule.EventClients.Add Me
End Sub

Private Sub IEventsClient_PropertyChanged(sender As Object, property As String)
    If TypeOf sender Is MyControl Then
        Select Case property
            Case "SomeProperty"
            '   DoSomething'
        End Select
    End If
End Sub
+2

All Articles