VBC09337 — Not allowed as a Public member of an object module
Severity: Error · Family: VBC (static semantics / abstract syntax tree) ·
Source metadata: VBCompileErrorInfo
A class module declares, as a public member, something an object cannot expose: a constant, a fixed-length string, an array, a user-defined type, a Declare statement, or a Global variable.
What a class module exposes is reached through an object of the class. A constant, a Declare and the module-wide Global belong to a module and not to an object, and an object's public variable is reached as a property is, which has no room for a fixed-length string, an array or a user-defined type.
MS-VBA reports the same error, with this message: Constants, fixed-length strings, arrays, user-defined types and Declare statements not allowed as Public members of object modules.
This code is raised by PublicMemberSemantics, at the member.
How it is raised
| Situation | Example | Resolution |
|---|---|---|
| A public constant. | Public Const Size As Long = 3 |
Declare it Private, or in a standard module. |
| A public fixed-length string. | Public Code As String * 4 |
Declare it Private, and expose a String property. |
| A public array, resizable or fixed-size. | Public Items() As Long |
Declare it Private, and expose procedures or a property that read and write it. |
| A public variable of a user-defined type, the class's own or a standard module's. | Public State As TState |
Declare it Private, and expose its fields through properties. |
A Declare, public or with no modifier, which is public. |
Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal ms As Long) |
Declare it Private. |
A Global variable, whatever its type. |
Global Count As Long |
Declare it Public, or in a standard module. |
Notes
A constant declared with no modifier (Const Size As Long = 3), and a variable declared with Dim, are private, and are not this.
A public variable of a class of a private Enum is VBC09336; one that is an array of it is this.
See also
- RD-VBAL §2.6.2 Semantic Compilation Errors
- VBC09338 Cannot define a Public user-defined type within an object module
⏮️ VBC09336 Private Enum and user defined types cannot be used in public members | ⏭️ VBC09338 Cannot define a Public user-defined type within an object module
ACCUEIL • HOME | ℹ️ BIENVENUE • WELCOME | 🧩 BÂTISSONS • BUILD | RD-VBAL | SDK | 🌐 rubberduckvba.ca