[Public] Event procedurename [(arglist)]
The Event statement has these parts:
Part | Description |
---|---|
Public | Optional. Entities declared with the Public modifier have public access. There are no restrictions on the use of public entities. |
procedurename | Required. Name of the event; follows standard variable naming conventions. |
The arglist argument has the following syntax and parts:
[ByVal | ByRef] varname[( )] [As type]
Part | Description |
---|---|
ByVal | Optional. Indicates that the argument is passed by value. ByVal is the default in Visual Basic. |
ByRef | Optional. Indicates that the argument is passed by reference. |
varname | Required. Name of the variable representing the argument being passed to the procedure; follows standard variable naming conventions. |
type | Optional. Data type of the argument passed to the procedure; may be Byte, Boolean, Char, Short, Integer, Long, Single, Double, Decimal, Date, String (variable length only), Object, a user-defined type, or an object type. |
Once the event has been declared, use the RaiseEvent statement to fire the event. An event can't be declared to return a value. A typical event might be declared and raised as shown in the following fragments:
' Declare an event at module level Event LogonCompleted (UserName as String) Sub RaiseEvent LogonCompleted("AntoineJan") End Sub
Note You can declare event arguments just as you do arguments of procedures, with the following exceptions: events cannot have named arguments, or Optional arguments. Events do not have return values.
Adding an Event to a Form | Adding Events to a Class | Adding Events to Classes | RaiseEvent Statement | Raising Events from Controls