Wrox Programmer Forums
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #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


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





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