Retrive Enum Value if I have Enum Constant Name as a String 
Author Message
 Retrive Enum Value if I have Enum Constant Name as a String

I have the following ENUM:

    Public Enum TemplateColor As Integer
        BlueDark = &H91A7CA
        BlueLight = &HDEE4EF
        GreenDark = &H669966
        GreenLight = &HE3ECE1
        TaupeDark = &HD6D8B8
        TaupeLight = &HF0F0E1
        GreyDark = &H7C8A94
        GreyLight = &HE9E9E9
        PurpleDark = &HA0A0C0
        PurpleLight = &HDEE4EF
    End Enum

How can retrieve the Enum Value if I only have the name of the constant as
a string(e.g.  GreyDark, BlueDark) .

I have tried the following to no avail:

   Dim t As TemplateColor
            Dim s As TemplateColor = t.Parse(GetType(TemplateColor),
strDarkColor)

Here, S only returns the value passed via strDarkColor.

L Anthony Johnson



Tue, 08 Feb 2005 21:46:47 GMT  
 Retrive Enum Value if I have Enum Constant Name as a String
If your goal is to get underlying value from an enum string (e.g "GreyDark")
your code looks fine apart that BlueLight and PurpleLight have the same
value.

HTH

--
Corrado Cavalli
UGIdotNET - http://www.ugidotnet.org



Tue, 08 Feb 2005 22:02:31 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Enum String Value (deriving from a Type Name and an Integer)

2. Assign a string value to an enum field

3. Fill combo box with enum names and values

4. Error: Constant expression required. When using Enum

5. How to list Enum constants in run-time?

6. Questions on VB5 declaration of Enum. Does anybody know how to do constant grouping using Enum?

7. Enum: count values at design time

8. Enum values not automatically popping up...

9. Getting variable names from an Enum (REPOST)

10. Get variable names from an Enum

11. Accessing Enum Values from an external object

12. Enum Registry Values?

 

 
Powered by phpBB® Forum Software