473,408 Members | 2,813 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,408 software developers and data experts.

Enumeration iteration

Hi

This has been irritating me for a while, so I think its not possible,
but hopefully Im wrong...

Is it possible to iterate an enum ? I want to do something like this.

for each enum in enumname
'do something (eg add item to select box)
next

thanks,

Matthew
Nov 20 '05 #1
5 4369
"Matthew" <ma****************@hotmail.com> schrieb
This has been irritating me for a while, so I think its not
possible, but hopefully Im wrong...

Is it possible to iterate an enum ? I want to do something like
this.

for each enum in enumname
'do something (eg add item to select box)
next

Dim Name As String
Dim Names As String()

Names = [Enum].GetNames(GetType(FormBorderStyle))

For Each Name In Names
Next

--
Armin

http://learn.to/quote
http://www.plig.net/nnq/nquote.html

Nov 20 '05 #2
* ma****************@hotmail.com (Matthew) scripsit:
This has been irritating me for a while, so I think its not possible,
but hopefully Im wrong...

Is it possible to iterate an enum ? I want to do something like this.

for each enum in enumname
'do something (eg add item to select box)
next


'Enum.GetNames', 'Enum.GetValues'.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

Improve your quoting style:
<http://learn.to/quote>
<http://www.plig.net/nnq/nquote.html>
Nov 20 '05 #3
Matthew,
If you want values instead of names (Armin showed you names) try:

Dim value As FormBorderStyle
Dim values As FormBorderStyle()

values = DirectCast([Enum].GetValues(GetType(FormBorderStyle)),
FormBorderStyle())

For Each value In values
Next

Also, System.Enum (the base type for all enums) have a number of other
useful shared functions, such as Format, Parse, IsDefined, and ToObject.
Remember because Enum is a keyword, you need to escape [Enum] in square
brackets to use the System.Enum type.

Hope this helps
Jay

"Matthew" <ma****************@hotmail.com> wrote in message
news:4f*************************@posting.google.co m...
Hi

This has been irritating me for a while, so I think its not possible,
but hopefully Im wrong...

Is it possible to iterate an enum ? I want to do something like this.

for each enum in enumname
'do something (eg add item to select box)
next

thanks,

Matthew

Nov 20 '05 #4
"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in message news:<Op**************@tk2msftngp13.phx.gbl>...
Matthew,
If you want values instead of names (Armin showed you names) try:

Dim value As FormBorderStyle
Dim values As FormBorderStyle()

values = DirectCast([Enum].GetValues(GetType(FormBorderStyle)),
FormBorderStyle())

For Each value In values
Next

Also, System.Enum (the base type for all enums) have a number of other
useful shared functions, such as Format, Parse, IsDefined, and ToObject.
Remember because Enum is a keyword, you need to escape [Enum] in square
brackets to use the System.Enum type.

Hope this helps
Jay

"Matthew" <ma****************@hotmail.com> wrote in message
news:4f*************************@posting.google.co m...
Hi

This has been irritating me for a while, so I think its not possible,
but hopefully Im wrong...

Is it possible to iterate an enum ? I want to do something like this.

for each enum in enumname
'do something (eg add item to select box)
next

thanks,

Matthew

Thanks very much Jay and Armin.
Nov 20 '05 #5
"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in message news:<Op**************@tk2msftngp13.phx.gbl>...
Matthew,
If you want values instead of names (Armin showed you names) try:

Dim value As FormBorderStyle
Dim values As FormBorderStyle()

values = DirectCast([Enum].GetValues(GetType(FormBorderStyle)),
FormBorderStyle())

For Each value In values
Next

Also, System.Enum (the base type for all enums) have a number of other
useful shared functions, such as Format, Parse, IsDefined, and ToObject.
Remember because Enum is a keyword, you need to escape [Enum] in square
brackets to use the System.Enum type.

Hope this helps
Jay

"Matthew" <ma****************@hotmail.com> wrote in message
news:4f*************************@posting.google.co m...
Hi

This has been irritating me for a while, so I think its not possible,
but hopefully Im wrong...

Is it possible to iterate an enum ? I want to do something like this.

for each enum in enumname
'do something (eg add item to select box)
next

thanks,

Matthew

For anyone interested here is how I have implemented the population of
a selectbox from an enum, using the advice of Jay and Armin: (XKeyType
is the Enum)

Dim val As XKeyType
Dim enumvals As XKeyType() =
DirectCast([Enum].GetValues(GetType(XKeyType)), XKeyType())
Dim li As ListItem
For Each val In enumvals
li = New ListItem
With li
.Value = val
.Text = [Enum].Format(GetType(XKeyType), val, "g")
End With
ddlist1.Items.Add(li)
Next
Nov 20 '05 #6

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

Similar topics

1
by: Justin Wright | last post by:
I know that I can set up an enumeration as follows ( just typed in quick so may have syntax errors ): <xsd:simpleType name="colors"> <xsd:restriction base="xsd:string"> <xsd:enumeration...
1
by: Amit Puri | last post by:
Please help me in the understanding functioning of an arraylist: I've having an arraylist function level, which I'm looping another object, and check the values of arraylist for existance with...
8
by: aevans1108 | last post by:
Greetings I can't seem to inherit enumerated values from a globally defined type in my XML schema. XmlSchema.Compile() doesn't like it. Here's the schema. <?xml version="1.0"...
2
by: Mark | last post by:
Assume you have an enumeration like PhoneType { Home, Business, Cell }. This enumeration corresponds with a lookup/dictionary table in your database like: phone_cd | phone_descr 1 ...
4
by: Marshal | last post by:
Sure... IEnumerable was inconvenient suggesting a separate class to service the enumeration, IEnumerator, and multiple operations: Current, MoveNext, Reset. (I'll warp the definition of "operation"...
1
by: Stefano G. | last post by:
I have a WSDL containing this enumeration type <xsd:simpleType name="item_type_enum"> <xsd:restriction base="xsd:string"> <xsd:enumeration value="VCD"/> <xsd:enumeration value="SVCD"/>...
27
by: Ben Finney | last post by:
Antoon Pardon wrote: > I just downloaded your enum module for python > and played a bit with it. IMO some of the behaviour makes it less > usefull. Feedback is appreciated. I'm hoping to...
3
by: Davidoff | last post by:
Hi, I parse an XML file with a XSD schema. One XmlNode has an attribute whose type is a restriction of xs:string : <xs:simpleType name="stypeDay"> <xs:restriction base="xs:string">...
0
by: news.emn.fr | last post by:
Hello, i got this attribute <xs:attribute name="jour"> <xs:simpleType> <xs:restriction base="stypeJour"> </xs:restriction> </xs:simpleType> </xs:attribute>
0
by: pamelafluente | last post by:
Hi guys, When deriving classes from a base class, I often find myself to use an enumeration to keep track fo the derived object type. I set it at New(). (I am aware that using overrides I...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
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...

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.