Table of Contents

VBC09324 — Invalid type for WithEvents variable

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

A WithEvents variable is declared as a type that cannot raise events to it.

MS-VBAL §5.2.3.1.2 WithEvents Variable Declarations requires the declared type to be a specific class that has at least one event member, and not the class defined by the class module that contains the declaration.

This code is raised by ClassModuleEventSemantics. The verbose detail names the variable, the type, and which of the rules it breaks.

How it is raised

Situation Example Resolution
The type is not a specific class. Private WithEvents Src As Object, or As Long Declare the variable as the class that raises the events: Private WithEvents Src As Source.
The class has no events. Private WithEvents Src As Silent, where Silent declares none Declare an event in the class, or handle nothing: remove WithEvents.
The type is the class of the module containing the declaration. Private WithEvents Me2 As Sink, in the class module Sink A class cannot handle its own events through a variable. Raise them with RaiseEvent and handle them in another class.

Notes

A type that is not resolved is not reported: it is not known to be wrong. Declaring a type that does not exist is reported where types are resolved.

See also


⏮️ VBC09323 Wrong number of arguments or invalid argument for event | ⏭️ VBC09325 Invalid event name


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