PDA

View Full Version : Enum Statement ? What?s It Used For?



Cyberdude
04-05-2006, 11:05 AM
In a previous thread posted by d_raghu9, TonyJollans recommended using ?enumeration? via the Enum statement. I was unable to understand the enumeration concept, and Tony tried to explain it to me. I decided this should be a separate thread so here it is folks.

I have defined a series of constants for the names of colors and planted the sequence in my Personal.xls workbook so I can use them by all my macros. The sequence of constants looks something like this:
Public Const NoColor& = 0
Public Const Red& = 3
Public Const SpclRed& = 51
Public Const SpclRedLt& = 36
Public Const SpclRedDk& = 38
Public Const DkRed& = 9
Public Const LtGreen& = 35
I assume that I could have used enumeration in my Personal.xls to create these definitions and write them something like this:
Public Enum MyColors
NoColor = 0
Red = 3
SpclRed = 51
SpclRedLt =36
SpclRedDk = 38
DkRed =9
LtGreen = 35
End Enum
Am I correct? My problem is that I don?t quite understand how the ?enum? technique is any better than the ?const? technique. What can I do with the ?enum? names that I can?t do with the ?const? names??

Killian
04-05-2006, 11:16 AM
It's a rather convenient way of organizing constants because in the IDE, they will appear in the Auto List Members dropdown as you type and in the object model viewer in their own group (rather than all the global constants being listed together).

Jacob Hilderbrand
04-05-2006, 11:27 AM
See if this helps. It allows you to see the constant names when you are calling a sub or a function.

Marcster
04-05-2006, 11:33 AM
Further to what Killian said...

http://www.cpearson.com/excel/Enums.htm

Marcster.

Cyberdude
04-05-2006, 12:16 PM
Excellent reference, Marcster! A key point I was missing is that I can Dim a variable using the Enum category name as a type for the variable. Got it!
Thanx, gang! :bow:

Marcster
04-06-2006, 07:50 AM
Glad you get it. Reckon you'll be using it alot more now.
I think it was introduced in version 2000.

Marcster.