Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Search | Today's Posts | Mark Forums Read
BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003
This is the forum to discuss the Wrox book Professional VB.NET 2003 by Bill Evjen, Billy Hollis, Rockford Lhotka, Tim McCarthy, Jonathan Pinnock, Rama Ramachandran, Bill Sheldon; ISBN: 9780764559921
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 6th, 2003, 11:03 AM
Registered User
 
Join Date: Jun 2003
Location: , , USA.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to saeta119
Default Enum in VB

I have this following code in C#
_mapRegions = new ListDictionary();
            foreach (RegionEnum region in Enum.GetValues(typeof(RegionEnum)))
                _mapRegions.Add(region, Enum.GetName(typeof(RegionEnum), region));

and in VB I tried

 _mapRegions = New ListDictionary()
            Dim region As RegionEnum = Nothing

            For Each region In System.Enum.GetValues(Type.GetType("RegionEnum"))
                _mapRegions.Add(region, System.Enum.GetName(Type.GetType("RegionEnum"), region))
            Next

but it throws an error, that the value cannot be null O.o ?

~Imagination is more important than knowledge~
  #2 (permalink)  
Old June 7th, 2003, 03:43 PM
Authorized User
 
Join Date: Jun 2003
Location: Cowes, IOW, United Kingdom.
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to JonathanC
Default

Hi

You can try this instead (notice the [YourFullNamespace] placeholder must be altered
example: "YourApplicationName.Form1+RegionEnum" should replace mine (do not add the [] brackets)

start .........

Dim myType As Type = Type.GetType("[YourFullNamespace+RegionEnum]")

For Each region In System.Enum.GetValues(myType)
 _mapRegions.Add(region, System.Enum.GetName(myType, region))
Next
........ end

Hope this helps you out.




Jonathan Crossland
http://www.jonathancrossland.com
  #3 (permalink)  
Old June 7th, 2003, 04:10 PM
Authorized User
 
Join Date: Jun 2003
Location: Cowes, IOW, United Kingdom.
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to JonathanC
Default


I was assuming in my post that the textual name of the type
was important to you.

However if the string name is not important and you will have access or knowledge of the type, you can can of course use

GetType(RegionEnum)




Jonathan Crossland
http://www.jonathancrossland.com
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
enum 2 names OneQuestion General .NET 4 January 2nd, 2008 02:50 PM
Enum gets initalized to first value mhshpk ASP.NET 2.0 Professional 2 September 4th, 2007 10:16 AM
enum toString() overloading kramis8 C# 0 November 21st, 2004 07:55 PM
Using Enum Type Mike2000 VB.NET 2002/2003 Basics 2 June 5th, 2003 05:20 AM



All times are GMT -4. The time now is 06:32 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.