5.2.3.4 Enum Declarations

global-enum-declaration = "global" enum-declaration 
public-enum-declaration = ["public"] enum-declaration 
private-enum-declaration = "private" enum-declaration 
enum-declaration = "enum" untyped-name EOS enum-member-list EOS "end" "enum" 
enum-member-list = enum-element *[EOS enum-element] 
enum-element = rem-statement / enum-member 
enum-member = untyped-name [ "=" constant-expression] 

<global-enum-declaration> provides syntactic compatibility with other dialects of the Basic language and historic versions of VBA.

Static Semantics.

  • A <global-enum-declaration> is not allowed in class modules.

  • The name value of the <untyped-name> that follows the Enum keyword (section 3.3.5.1) is the enum name of the containing <enum-declaration>.

  • An Enum declaration that is part of a <global-variable-declaration> or <public-enum-declaration> declares a public Enum type. The Enum type and its Enum members are accessible within the enclosing project. If the enclosing module is a class module or a procedural module that is not a private module, then the Enum type and its Enum members are also accessible within projects that reference the enclosing project.

  • An Enum declaration that is part of a <private-enum-declaration> declares a private Enum type. The Enum type and its enum members are accessible within the enclosing module.

  • The enum name of a <private-enum-declaration> cannot be the same as the enum name of any other <enum-declaration> or as the UDT name of a <udt-declaration> within the same module.

  • The enum name of a <public-enum-declaration> cannot be the same as the enum name of any other public <enum-declaration> or the UDT name of any public <udt-declaration> within any module of the project that contains it.

  • The enum name of a <public-enum-declaration> cannot be the same as the name of any project or library within the current VBA Environment or the same name as any module within the project that contains the <enum-declaration>.

  • At least one <enum-element> in an <enum-member-list> MUST consist of a <enum-member>.

  • The enum member name of an <enum-member> is the name value of its <untyped-name>.

  • Each <enum-member> within a <enum-member-list> MUST have a different enum member name.

  • An enum member name might not be the same as any variable name, or constant name that is defined within the same module.

  • If an <enum-member> contains a <constant-expression>, the data value of the <constant-expression> MUST be coercible to value type Long.

  • The <constant-expression> of an <enum-member> might not contain a reference to the enum member name of that <enum-member>.

  • The <constant-expression> of an <enum-member> might not contain a reference to the enum member name of any <enum-member> that it precedes in its containing <enum-member-list>

  • The <constant-expression> of an <enum-member> might not contain a reference to the enum member name of any <enum-member> of any <enum-declaration> that it precedes in the containing module declaration section.

  • If an <enum-member> contains a <constant-expression>, the data value of the <enum-member> is the data value of its <constant-expression> coerced to value type Long. If an <enum-member> does not contain a <constant-expression> and it is the first element of a <enum-member-list> its data value is 0. If an <enum-member> does not contain a <constant-expression> and is not the first element of a <enum-member-list> its data value is 1 greater than the data value of the preceding element of its containing <enum-member-list>.

  • The declared type of a <enum-member> is Long.

  • When an enum name (possibly qualified by a project) appears in an <as-type> clause of any declaration, the meaning is the same as if the enum name was replaced with the declared type Long.