Solved

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

Posted on 2006-11-14
2
234 Views
Last Modified: 2010-08-05
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
Comment
Question by:Artform04
2 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 250 total points
ID: 17937334
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
 
LVL 8

Expert Comment

by:doraiswamy
ID: 17937469
Also when you declare objCWE you have to declare it "WithEvents" as below:

Dim WithEvents objCWE as ClassWithEvents = New ClassWithEvents
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question