Solved

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

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Copy a file to a share on a Domain 3 58
Open a folder with partial name 14 29
Duplicate a row 2 33
Library to convert HTML to PDF. 8 46
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

744 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

8 Experts available now in Live!

Get 1:1 Help Now