Solved

Looking for an alternative to enumeration in C

Posted on 2006-07-13
4
162 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 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Problem to the message 13 62
MS Access Search and Replace Using VBA 6 40
Adding to a VBA? 6 46
message box in access 4 33
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

728 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now