Table of Contents

VBC09336 — Private Enum and user defined types cannot be used in public members

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

A public member is declared with a type that is private to its module: a private Enum, or, in a class module, a private user-defined type.

What a public member is declared with is what the code of other modules has to name to use it, and a private type cannot be named outside its module. A variable, the result of a function or a property, and a parameter of a procedure, a property, an event or a Declare are each declared with a type; so is an array of one.

MS-VBA reports the same error, with this message: Private Enum and user defined types cannot be used as parameters or return types for public procedures, public data members, or fields of public user defined types.

This code is raised by PublicMemberSemantics, at the member, or at the parameter that is declared with the type.

How it is raised

Situation Example Resolution
A public variable of a private Enum. Private Enum E … Public V As E Make the Enum public, or the variable private.
The result of a public function or property, a private Enum. Public Function F() As E Make the Enum public, or the procedure Private (or Friend, in a class).
A parameter of a public procedure, property or Declare, a private Enum. Public Sub S(ByVal x As E) The same.
A procedure with no modifier, which is public. Function F() As E The same.
In a class module, a public member of a private user-defined type. Private Type T … Public Function F() As T Make the member Private or Friend.
In a class module, an event with a parameter of a private type or Enum. Public Event Moved(ByRef p As T) Use a type the event's handlers can name.

Notes

What MS-VBA does is not all that its message says, and not all that MS-VBAL says; RD-VBA does what MS-VBA does (recorded in Excel):

  • In a standard module, a public member may be declared with the module's own private user-defined types; only a private Enum is refused.
  • A field of a Public Type may be of a private type or a private Enum, though the message names fields of public user-defined types.
  • A Friend member is not public, and may be declared with the class's private types.
  • A public member of a class may be declared with a standard module's Public Type, which MS-VBAL §5.3.1.5 refuses for a parameter.

A public variable of a class module that is a user-defined type is VBC09337, not this: MS-VBA reports that one.

See also


⏮️ VBC09335 Type-declaration character does not match declared data type | ⏭️ VBC09337 Not allowed as a Public member of an object module


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