Solved

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

Posted on 2006-11-14
2
252 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

751 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