Solved

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

Posted on 2006-11-14
2
224 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

948 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now