Solved

Looking for an alternative to enumeration in C

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
vb6 connector to SQL Server 2 37
Convert VB6 MSXML2.ServerXMLHTTP process to C# 2 47
Visual Studio search word table and return Cell index 8 61
Spell Check in VB6 13 114
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

803 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