Creating

It is possibe to create your own enumerations.
All constant values are treated as Long integers.
The word "Enum" is short for Enumeration.

Public Enum enTemperature 
   enConstant1 = 0
   enConstant2 = 1
   enConstant3 = 2
End Enum

Always prefix your enumeration with the characters "en".
Always prefix the values with the characters "en".
When you refer to the constant in the code always prefix it with the enumeration name.

Call MsgBox(enTemperature.enConstant1) 
Call MsgBox(enConstant1) ' this is more confusing

Example 1

If you don't specify any numerical values the enumeration will start at 0 and each subsequent value will incrememt by 1.

Public Enum enTemperatue 
   enConstant1 ' this will have the value 0
   enConstant2 ' this will have the value 1
   enConstant3 = 20
   enConstant4 ' this will have the value 21
End Enum

Example 2

You can also provide your own numerical values.

Public Enum enTemperatue 
   enConstant1 = -20
   enConstant2 = 0
   enConstant3 = 10
   enConstant4 = 35
End Enum

Example 3

You can also use an existing enumeration constant to determine the value of another one.

Public Enum enTemperatue 
   enConstant1 = 100
   enConstant2 = enConstant1 + 20
   enConstant3 = enConstant2 + 30
   enConstant4 = enConstant3 + 100
End Enum

Case Sensitive

You can declare enumerations in mixed case but ..
When you use them in your code if you type them in lowercase, the original declaration will be changed to lowercase.


Other Information

Beware using floating point values with Enum.
This functionality was added in Office 2000.
The integers are rounded to the largest integer.


© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext