Solved

How to iterate through enumeration in VB.net

Posted on 2008-10-08
1
2,457 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

636 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