
Visual Basic is full of enumerated constants (types) that make programming easier; the meaning of MsgBox value 4 is obscure but the meaning of the value vbYesNo is obvious. Summing up all possible types, states, roles or whatever entities you're dealing with will help you ascertain that you don't forget some cases, causing bugs in the program. By specifying your own enumerated constants for values used within your own organization you make your own code more reliable and easier to maintain.
By default, enumerated constants hold a series of consecutive longs starting from zero. This example assigns values 0 to 3 to four security levels:
Public Enum sleSecLevels
sleAdmin
slePowerUser
sleUser
sleGuest
End EnumThe security routines in the rest of the application can now refer to sleAdmin and the other constants instead of their numeric values. The three-letter lower case prefix helps you recognize the constant as part of this enumerated set when you see it in code.
Working with enumerated constants is encouraged by the Select Case from Enum Builder .
You can add a constant to the enumerated type without having to move to the location where it is declared using Add Constant To Enum
Start this dialog from using Alt-CCE (Code-vb - Constant - new E num)
What is specified here is automatically added to both the enumerated type and the individual constants. In the example: sle
Name of the Enumerated Type
Add the constants to be included in this textbox. Each constant on a separate line. The following variants are allowed:
1. Without starting point, as above example. First value is 0
2. With starting point, each entry has integer value one higher then the previous item
3. Each a separate constant
Module in which the constant is to be placed (only in case of Public accessibility ).
Create enumerated type and close dialog.
Close dialog without creating enumerated type.
Starts this Help topic
Determines from which modules in the application the enumerated type is visible.Accessibility
The enumerated type is visible only from the current module.
The enumerated type is visible only from all modules.
(= public) The enumerated type does not have explicit accessibility.