Class Module Level


SS



Module1

Add a new standard module called Module1

Public Sub DoSomething() 
    Dim class1 As ClassWithEvents
    Set class1 = New ClassWithEvents
    
    Dim class2 As ClassHandlyingEvents
    Set class2 = New ClassHandlyingEvents
    Set class2.myEvents = class1
        
    Call class1.Method_SetText("text 1")
    Call class1.Method_SetText("text 2")
    Call class1.Method_SetText("text 3")
End Sub


ClassHandlyingEvents

Add a new class module called ClassHandlyingEvents

Public WithEvents myEvents As ClassWithEvents 

Private Sub myEvents_MyTextChangedEvent(ByVal Text As String)
    Debug.Print Text
End Sub


ClassWithEvents

Add a new class module called ClassWithEvents


Private myField As String 

Public Function Method_SetText(ByVal myString As String)
    myField = myString
    
'event is raised every time this property is changed
    RaiseEvent MyTextChangedEvent(myString) End Function
End Function



© 2019 Better Solutions Limited. All Rights Reserved. © 2019 Better Solutions Limited TopPrevNext