Most objects raise events, which can be used to great effect in your VB application and add a further dimension to OLE automation. Rather than the usual one-way conversation, in which your application is forever telling the server what to do or asking it to provide information about its properties, making use of the server's events is like giving the server a "voice," allowing it to report back to your application. You might, for example, receive an event notification from the server when certain tasks are about to be or have been completed.
You enable your application to listen for these event notifications by using the WithEvents keyword. Use of the WithEvents keyword is restricted to variables defined in the declarations section of your module. Only object modules—that is, class and form modules—can contain variables declared using the WithEvents keyword. Once a module-level variable is declared as WithEvents, you can program against this event, enabling your application to respond to the changing state of the OLE automation server.
|
For more information about the WithEvents keyword see the entries for the Dim, Friend, Private, and Public statements in Chapter 7.