Table of Contents

VBC09326 — Invalid event handler

Severity: Error  ·  Family: VBC (static semantics / abstract syntax tree)  ·  Source metadata: VBCompileErrorInfo

A procedure that is named as the handler of an event is not a valid one.

MS-VBAL §5.3.1.8 Event Handler Declarations makes a procedure of a class module the handler of an event when its name is VariableName_EventName: the name of a WithEvents variable of the same module, then an underscore, then the name of an event of the class that variable is declared as. Such a handler is invalid when it is not a subroutine, or when its parameter list is not compatible with the parameter list of the event.

This code is raised by ClassModuleEventSemantics. The verbose detail names the handler, the event, and what does not match.

How it is raised

Situation Example, for Event Changed(ByVal Value As Long) of Src Resolution
The handler is a function or a property. Private Function Src_Changed(ByVal Value As Long) As Long Declare a subroutine.
The handler has another number of parameters. Private Sub Src_Changed() Give it the event's parameters.
A parameter is of another type. Private Sub Src_Changed(ByVal Value As String) Declare the event's type.
A parameter is passed by another mechanism. Private Sub Src_Changed(ByRef Value As Long) Pass it the way the event does.

Notes

A compatible parameter list may differ from the event's in the names of its parameters, and in whether the mechanism is written out: Count As Long handles ByRef Count As Long.

A procedure whose name begins with the name of a WithEvents variable and an underscore, but does not end with the name of an event of the variable's class, is not a handler of anything, and is not checked. Neither is one named for a variable that is not declared WithEvents.

See also


⏮️ VBC09325 Invalid event name | ⏭️ VBC09327 ByVal argument not allowed here


ACCUEIL • HOME | ℹ️ BIENVENUE • WELCOME | 🧩 BÂTISSONS • BUILD | RD-VBAL | SDK | 🌐 rubberduckvba.ca