Enum newbie question
Author Message
Enum newbie question

Let's say I have:

Enum Mycolors
red
cyan
yellow
end Enum

How can I check if another variable is an element of Mycolors. Also, how
can I find out how many colors I have enumerated (something along the
lines of UBound).

Thanks

Sun, 25 Mar 2001 03:00:00 GMT
Enum newbie question
An Enum is basically a convenient way of grouping Constants of type Long.

The language doesn't provide a direct way of determining if a value
matches one of an Enum's constants.  Sometimes it is handy
to define lowerbound and upperbound elements.

Enum Mycolors
colorLBound
red
cyan
yellow
colorUBound
End Enum

Calculate number of elements
Count = colorUBound - colorLBound + 1

Iterate through them:
For i = colorLBound + 1 to colorUBound -1
Next i

Determine if a value equals the value of one of the elements
If x > colorLBound and x < colorUBound Then
'value of x matches one of the elements
End If

The nice part of this technique is that you can
add elements to the Enum without breaking your
code.

Michael Keller

Quote:

>Let's say I have:

>Enum Mycolors
>    red
>    cyan
>    yellow
>end Enum

>How can I check if another variable is an element of Mycolors. Also, how
>can I find out how many colors I have enumerated (something along the
>lines of UBound).

>Thanks

Tue, 27 Mar 2001 03:00:00 GMT

 Page 1 of 1 [ 2 post ]

Relevant Pages