Appearance of an event and transmission of its message is accomplished by specification RaiseEvent.
Specification RaiseEvent is used only for events declared explicitly.
Use RaiseEvent specification is exemplified in the following source code sequence developed in VB.NET:
Module Module1 'defining event handler Public Sub OpDiferenta(ByVal a As Integer, ByVal b As Integer) Dim dif As Integer dif = a - b MsgBox("Substraction value is: " & CStr(dif)) End Sub 'defining an event Public Event Calcul(ByVal x As Integer, ByVal y As Integer) 'defining procdeure for event-event handler association Public Sub SetUpEventHandlerDif(ByVal a As Integer, ByVal b As Integer) AddHandler Calcul, AddressOf OpDiferenta End Sub Sub Main() Dim x As Integer Dim y As Integer x = 10 y = 8 If x > y Then SetUpEventHandlerDif(x, y) End If '1st call of event handler RaiseEvent Calcul(x, y) '2nd call of event handler RaiseEvent Calcul(x, y) End Sub End Module
Previous example defines the event Calcul, the event handler OpDiferenta and the association of event and event handler by Sub procedure called SetUpEventHandlerDif.
The VB.NET project has the type Console Application, and contains the procedure Main in the module created by Visual Studio.
In Main procedure there are defined two variables of type Integer, the event is associated with the event handler if the condition x>y is accomplished and the message of the event is transmitted twice through RaiseEvent specification. Thus, there are twice callings of the event handler OpDiferenta.