Solved

Handles Clause requires a WithEvents variable

Posted on 2008-10-23
6
1,714 Views
Last Modified: 2012-06-27
Hi

I have a app that is using a third party library to connect a device to a serial port. All is working well if I stay with one form, but I need to maintain the open serial connection across forms.

I have a variable defined in a module

Public WithEvents ph as ProtocolHandler

But when I try to add a sub on another form that Handles ph.ReaderDateTimeChanged I get a compile error

Handles clause requires a WithEvents variable defined in the containing type or one of its base types.

If I try to define ph locally as Private WithEvents ph as ProtocolHandler, the error goes away, but the protocols setup in the module are lost.

Thanks
0
Comment
Question by:nsfranklin
  • 3
  • 2
6 Comments
 
LVL 14

Expert Comment

by:Omego2K
ID: 22786515
Have you tried declaring it private, but making a property to return the value?
0
 

Author Comment

by:nsfranklin
ID: 22786610
sorry could you provide an example
0
 
LVL 14

Expert Comment

by:Omego2K
ID: 22786780
Something like this?
Private WithEvents ph as ProtocolHandler
 

Public ReadOnly Property SomeName As ProtocolHandler

   Get

       return ph

   End Get

End Property

Open in new window

0
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.

 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 250 total points
ID: 22788545
You can assign your Form variable to be the same one as the Module in the Load() event like this:

Module Module1

    Public WithEvents ph As ProtocolHandler

End Module

Public Class Form1

    Private WithEvents ph As ProtocolHandler

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ph = Module1.ph
    End Sub

End Class
0
 

Author Comment

by:nsfranklin
ID: 22795736
Thanks Idle Mind, your solution worked great, sorry Omego2K
0
 

Author Closing Comment

by:nsfranklin
ID: 31509157
Thanks for your prompt reply and solution.
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

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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

895 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

16 Experts available now in Live!

Get 1:1 Help Now