473,396 Members | 1,706 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,396 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 10407
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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,...

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.