How to: Raise an Event (Visual Basic)

This example defines an event (TimeExpired) and uses the RaiseEvent statement to cause the event to occur.

Example

Public Event TimeExpired(ByVal Status As String)
Public Sub RaiseTimeExpiredEvent()
    RaiseEvent TimeExpired("Your time has run out")
End Sub
Public Event TimeExpired(ByVal Status As String)
Public Sub RaiseTimeExpiredEvent()
    RaiseEvent TimeExpired("Your time has run out")
End Sub

This code example is also available as an IntelliSense code snippet. In the code snippet picker, it is located in Visual Basic Language. For more information, see How to: Insert Snippets Into Your Code (Visual Basic).

Compiling the Code

This example requires:

  • Access to the members of the System namespace. Add an Imports statement if you are not fully qualifying member names in your code. For more information, see Imports Statement (.NET Namespace and Type).

  • The Event statement to be at class level and not inside any procedure.

  • The RaiseEvent statement to be inside some procedure in your application.

See Also

Tasks

How to: Create an Event and Handler (Visual Basic)

Concepts

Events and Event Handlers

Reference

Event Statement

RaiseEvent Statement

Other Resources

Events in Visual Basic