Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 260
  • Last Modified:

How to make my event handler work...??

Hi, I have written a simple class below but i'm quite new to the whole object orientated approach. I am having difficulty in making the Handler work for my event...

The sub updateStatus is called elsewhere in my code, which should then in theory raise the event changeStatusText.  However, this line executes fine but my handler never seems to come into play.  

The class is below and any help would be appreciated. Thanks, Phil.



Public Class ClassWithEvents

#Region "objs"
    Public WithEvents objCWE As ClassWithEvents
#End Region



#Region "events"
    Public Event changeStatusText(ByVal strStatus As String)
#End Region



#Region "subs"
    'raises the change status event
    Public Sub updateStatus(ByVal strStatus As String)
        RaiseEvent changeStatusText(strStatus)
    End Sub

    'handles the change status
    Private Sub objCWE_ChangeStatusText(ByVal strStatus As String) Handles objCWE.changeStatusText
        AddUnit.stMessages.Text = strStatus
    End Sub
#End Region


End Class
0
Artform04
Asked:
Artform04
1 Solution
 
TimCotteeCommented:
Hi Artform04,

The handler needs to be in the calling class, not the called class

Private Sub StartHere()
    Dim objCWE as ClassWithEvents = New ClassWithEvents
    objCWE.updateStatus("New Status")
End Sub

Private Sub objCWE_ChangeStatusText(ByVal strStatus As String) Handles objCWE.changeStatusText
    AddUnit.stMessages.Text = strStatus
End Sub


Tim Cottee
0
 
doraiswamyCommented:
Also when you declare objCWE you have to declare it "WithEvents" as below:

Dim WithEvents objCWE as ClassWithEvents = New ClassWithEvents
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now