Assign a string value to an enum field 
Author Message
 Assign a string value to an enum field

In the code:

Public Enum CarMaker
  Ford
  GM
  Honda
End Enum

Public Class Car
  Public Maker as CarMaker
End Class

..
Dim c as new Car
Car.Maker = "Ford"   <--- error
..

I want to assign a string to a enum field? I would like a way for the
class Car to search for an enum "Ford" an if none exist throw an error,
is this possible ?

thanx

*** Sent via Developersdex http://www.*-*-*.com/ ***
Don't just participate in USENET...get rewarded for it!



Sun, 14 Aug 2005 02:37:50 GMT  
 Assign a string value to an enum field

says...

Quote:
> In the code:

> Public Enum CarMaker
>   Ford
>   GM
>   Honda
> End Enum

> Public Class Car
>   Public Maker as CarMaker
> End Class

> ..
> Dim c as new Car
> Car.Maker = "Ford"   <--- error
> ..

> I want to assign a string to a enum field? I would like a way for the
> class Car to search for an enum "Ford" an if none exist throw an error,
> is this possible ?

Use the Enum.Parse() method.

--
Patrick Steele
Microsoft .NET MVP
http://radio.weblogs.com/0110109



Sun, 14 Aug 2005 02:50:26 GMT  
 Assign a string value to an enum field
Thanx Patrick, just what I wanted!

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Sun, 14 Aug 2005 04:43:44 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Retrive Enum Value if I have Enum Constant Name as a String

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

3. ASSIGN STRING NULL VALUE?

4. Why my string variable can't be assigned with a value

5. Assigning function name to a string value

6. Assigning string value in Orale.

7. Newbie - assigning calculated value to table field

8. Assigning Rank and Points based on a field value

9. Assigning new values to fields

10. Assign Value to Enterprise Project Field

11. Assign the null value to DB2 fields.

12. Assigning Null Values to data bound fields using remote data control

 

 
Powered by phpBB® Forum Software