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  
 
 [ 2 post ] 

 Relevant Pages 

1. Const Vs. Enum -- Newbie-type question

2. enum session. newbie question

3. Retrive Enum Value if I have Enum Constant Name as a String

4. Class Module Enum Question

5. Simple Enum Question

6. another enum question

7. 2 questions... Enum INI's and plugins

8. Enum Question

9. Enum Question

10. Questions on VB5 declaration of Enum. Does anybody know how to do constant grouping using Enum?

11. Newbie question: Session_OnEnd question

12. Resizing forms question (newbie question)

 

 
Powered by phpBB® Forum Software