Table of contents
TOC
Collapse the table of content
Expand the table of content

Enum Statement

office 365 dev account|Last Updated: 6/12/2017
|
1 Contributor

Declares a type for an enumeration.

Syntax

[ Public |Private ] Enumname

membername [= constantexpression ] membername [= constantexpression ] . . .End Enum The Enum statement has these parts:

PartDescription
PublicOptional. Specifies that the Enum type is visible throughout theproject. Enum types are Public by default.
PrivateOptional. Specifies that the Enum type is visible only within themodule in which it appears.
nameRequired. The name of the Enum type. The name must be a valid Visual Basic identifier and is specified as the type when declaringvariables orparameters of the Enum type.
membernameRequired. A valid Visual Basic identifier specifying the name by which a constituent element of the Enum type will be known.
constantexpressionOptional. Value of the element (evaluates to a Long ). If no constantexpression is specified, the value assigned is either zero (if it is the first membername ), or 1 greater than the value of the immediately preceding membername.

Remarks Enumeration variables are variables declared with an Enum type. Both variables and parameters can be declared with an Enum type. The elements of the Enum type are initialized to constant values within the Enum statement. The assigned values can't be modified atrun time and can include both positive and negative numbers. For example:

Enum SecurityLevel 
 IllegalEntry = -1 
 SecurityLevel1 = 0 
 SecurityLevel2 = 1 
End Enum 

An Enum statement can appear only atmodule level. Once the Enum type is defined, it can be used to declare variables, parameters, orprocedures returning its type. You can't qualify an Enum type name with a module name. PublicEnum types in aclass module are not members of the class; however, they are written to thetype library. Enum types defined instandard modules aren't written to type libraries. Public Enum types of the same name can't be defined in both standard modules and class modules, since they share the same name space. When two Enum types in different type libraries have the same name, but different elements, a reference to a variable of the type depends on which type library has higher priority in the References. You can't use an Enum type as the target in a With block.

Example

The following example shows the Enum statement used to define a collection of named constants. In this case, the constants are colors you might choose to design data entry forms for a database.

Public Enum InterfaceColors 
 icMistyRose = &;HE1E4FF&; 
 icSlateGray = &;H908070&; 
 icDodgerBlue = &;HFF901E&; 
 icDeepSkyBlue = &;HFFBF00&; 
 icSpringGreen = &;H7FFF00&; 
 icForestGreen = &;H228B22&; 
 icGoldenrod = &;H20A5DA&; 
 icFirebrick = &;H2222B2&; 
End Enum
© 2017 Microsoft