Event Statement |
Named Arguments
No
Syntax
Public Event eventName [(arglist)]
eventName
Use: Required
Data Type: String
The name of the event.
arglist
Optional; has the following syntax:
[ByVal | ByRef] varname[( )] [As type]
ByVal
Use: Optional
The argument is passed by value; that is, a local copy of the variable is assigned the value of the argument.
ByRef
Use: Optional
The argument is passed by reference; that is, the local variable is simply a reference to the argument being passed. All changes made to the local variable are reflected in the calling argument. ByRef is the default method of passing variables.
varname
Use: Required
The name of the local variable containing either the reference or value of the argument.
type
Use: Optional
The data type of the argument. Can be any data type.
Description
Defines a custom event that the object can raise at any time using the RaiseEvent statement.
Rules at a Glance
The event declaration must be Public so that it's visible outside the object module; it can't be declared as Friend or Private.
An Event statement can appear only in the Declarations section of an object module—that is, in a form or class module.
Example
The following snippet demonstrates how you can use an event to communicate a status message back to the client application. To take advantage of this functionality, the client must declare a reference to this class using the WithEvents keyword.
Public Event Status(Message As String) Private Function UpdateRecords() ...
Get VB & VBA in a Nutshell: The Language now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.