Solved

How to iterate through enumeration in VB.net

Posted on 2008-10-08
1
2,422 Views
Last Modified: 2008-10-08
Hi,
I would like to iterate through an enumeration and capture the names and coresponding values. The problem I am running into, is when I attempt to capture the enumeration type using the following line:

Dim mytype As Type = Type.GetType("Bold.Providers.CRMDataProvider.CaseViews")

the type is "Nothing". Am I not correctly qualifying the namespace where my enumeration exists?


Dim mytype As Type = Type.GetType("Providers.CRMDataProvider.CaseViews")

            Dim names() As String = [Enum].GetNames(Type.GetType("Bold.Providers.CRMDataProvider.CaseViews"))

            Dim vals As Array = [Enum].GetValues(Type.GetType("Bold.Providers.CRMDataProvider.CaseViews"))
 

            For Each Name As String In names

                Debug.Print(Name)

            Next
 

            For Each value As Object In vals

                Debug.Print(value)

            Next

Open in new window

0
Comment
Question by:lbargers
1 Comment
 
LVL 25

Accepted Solution

by:
Luis Pérez earned 125 total points
ID: 22673416
You can obtain the type by declaring a variable of that enumerated type and calling it's GetType function.  If you do that, you can be sure that Type returned will not be nothing.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

863 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

27 Experts available now in Live!

Get 1:1 Help Now