I am trying to declare a variable in a VB6 module as follows:
Public WithEvents MyObject As MyClass
The help files say that WithEvents can only be used in class modules. Why can’t it be used in .bas modules?
The legacy code I am working has an object declared globally in a module. I want to add WithEvents to this declaration but I need to keep the object global because many other forms etc refer to the object. How can I achieve this with minimal disruption to the code?
Write a class that accepts your global object as a parameter and sinks its events.
Create an instance of this class in your
.basmodule.