Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Looking for an alternative to enumeration in C

Posted on 2006-07-13
4
Medium Priority
?
174 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Suggested Courses

636 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