Solved

Looking for an alternative to enumeration in C

Posted on 2006-07-13
4
164 Views
Last Modified: 2010-04-30
something that would let me do this:

   Enum Color ( red = 0, yellow = 1, green = 2 )

if Color = red then ...
if Color = yellow then ...
if Color = green then ...

0
Comment
Question by:AlexF777
  • 3
4 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 17099168
Public Enum MyColor
  MyRed  = 0
  MyYellow = 1
  MyGreen = 2
End Enum


dim vColor as MyColor

select case vColor
  case MyColor.MyRed:
     ...
  case MyColor.MyYellow:
     ...

end select
0
 
LVL 19

Expert Comment

by:BrianGEFF719
ID: 17102828
You know VB already has a type that does just this :0


Dim myColor As ColorConstants
myColor = vbBlue

Select Case myColor
 Case vbRed
  MsgBox "You're Red"
 Case vbBlue
  MsgBox "Youre Blue"
 Case Else
  MsgBox "You're not red or blue :("
End Select
0
 
LVL 19

Expert Comment

by:BrianGEFF719
ID: 17102843
The advantage to using the 'ColorConstants' type is that you can freely apply it to other controls, it is the vb standard.

For example:


Dim myColor As ColorConstants
myColor = vbBlue

'// apply our color to the forecolor of a label
label1.forecolor = myColor  
0
 
LVL 19

Expert Comment

by:BrianGEFF719
ID: 17102851
Although, these suggestions do not really answer your question, however i felt it might be a good idea to shed some light on this.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question