Handles Clause requires a WithEvents variable
Posted on 2008-10-23
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.