473,434 Members | 1,593 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,434 software developers and data experts.

HOWTO? Iterate all legal values of an ENUM

I see this was posted a long time ago, but it has since expired.

Given....

Public Enum Fruit
Apple
Banana
Cherry
Peach
Strawberry
Tomatoe
End Enum

I'd like to be do something of this flavor in VB.NET....

Dim frMyFruit as Fruit

For Each frMyFruit in Fruit
...
Next

Of course it complains that "Fruit" is a type in the FOR EACH.
Does the language or runtime provide SOME WAY to find all legal values?

TIA for your learned advice.
Best regards,
Lee Gillie, Spokane
Nov 21 '05 #1
2 10409
Never mind, I think I see it...

Dim frMyFruit as Fruit

For Each frMyFruit In [Enum].GetValues(GetType(Fruit))
...
Next

- Lee

Lee Gillie wrote:
I see this was posted a long time ago, but it has since expired.

Given....

Public Enum Fruit
Apple
Banana
Cherry
Peach
Strawberry
Tomatoe
End Enum

I'd like to be do something of this flavor in VB.NET....

Dim frMyFruit as Fruit

For Each frMyFruit in Fruit
...
Next

Of course it complains that "Fruit" is a type in the FOR EACH.
Does the language or runtime provide SOME WAY to find all legal values?

TIA for your learned advice.
Best regards,
Lee Gillie, Spokane

Nov 21 '05 #2
"Lee Gillie" <Le*@nospam.odp.com> schrieb:
Given....

Public Enum Fruit
Apple
Banana
Cherry
Peach
Strawberry
Tomatoe
End Enum

I'd like to be do something of this flavor in VB.NET....

Dim frMyFruit as Fruit

For Each frMyFruit in Fruit
...
Next

Of course it complains that "Fruit" is a type in the FOR EACH.
Does the language or runtime provide SOME WAY to find all legal values?


\\\
For Each f As Fruit In [Enum].GetValues(GetType(Fruit))
...
Next f
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Billy Porter | last post by:
Greetings, If I populate an ArrayList with values from, let's say, the Keys enum: ArrayList a = new ArrayList(); a.Add(Keys.Home); a.Add(Keys.End); ....then how do I iterate through the...
2
by: Mark | last post by:
Assume you've declared an enum .... public enum MyEnum { First, Second, Third } Without knowing the values of the enum, is it possible to iterate through all the possible values...
1
by: Roy | last post by:
Hi, I have a problem that I have been working with for a while. I need to be able from server side (asp.net) to detect that the file i'm streaming down to the client is saved...
2
by: John A Grandy | last post by:
how to iterate through the members of an Enum ? Enum EnumAction None = 0 Action1 = 1 Action2 = 2 Action3 = 3 Action4 = 4 End Enum
6
by: Steven Woody | last post by:
is there any way in C leting me iterate all integer constants in a enum type ? their values might not be continue. thanks. - woody
8
by: Bart Simpson | last post by:
typedef enum { ACCESS_DENIED = 1, ACCESS_READ_ONLY = 2, ACCESS_READ_WRITE = 4 }AccessTypeEnum ; Is this legal? - can I have 'gaps' in the enumeration integer values as above ?
13
by: Jorn Ronnow | last post by:
I'm a bit confused here, since the help in M$ Visual Studio 2005 states the syntax for enum as: enum {enum-list} ; So, it would be possible to write: enum Protocol_t : unsigned char {...
2
by: garth | last post by:
Hi, Is it possible to iterate over and enumerated type in C#? If so please can you paste a simple exampel up that covers the whole process. Thanks
15
by: Frank | last post by:
Before I start, please let's not discuss whether goto is evil or not. For generated code, this can make perfect sense. It would be interesting to know a trick how to get C to do a goto to an...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.