|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
enum item from stringavailable: Enum EggTypes OverEasy Scrambled Poached End Enum Public myCookStyle as EggTypes Public Sub OrderEggs(Request as String) 'Here is where I want to set the value of 'myCookStyle based on the Request String '... and NO I cannot change this code... '(This code just demonstrates what I am doing.. I ONLY have the string 'or at BEST I have an integer that corosponds to the Integer value 'of the EggType) myCookStyle = ???? End Sub Thanks in Advance... -- --Zorpie In article <3F4A32CB-CCFF-4605-833E-0FAC63788***@microsoft.com>, Zorpiedoman wrote:
Show quoteHide quote > I want to set a property, that is an enum type, but I only have the string For the string value, you might want to look at Enum.Parse> available: > > Enum EggTypes > OverEasy > Scrambled > Poached > End Enum > > Public myCookStyle as EggTypes > > Public Sub OrderEggs(Request as String) > 'Here is where I want to set the value of > 'myCookStyle based on the Request String > '... and NO I cannot change this code... > '(This code just demonstrates what I am doing.. I ONLY have the string > 'or at BEST I have an integer that corosponds to the Integer value > 'of the EggType) > > myCookStyle = ???? > End Sub > > > Thanks in Advance... > myCookStyle = _ CType ([Enum].Parse (GetType (EggTypes), _ Request), EggTypes) This will of course throw and exception if the value is not defined in the enum. You can use the Enum.GetNames if you would like to do a comparison ahead of time :) -- Tom Shelton [MVP] Hey Zorpiedoman,
you can use the Enum.Parse method to convert a string to the corresponding enum value like this: Dim myCookStyle As EggTypes = CType([Enum].Parse(GetType(EggTypes), Request), EggTypes) Regards, Peter Lillevold http://blogs.eternia.cc/peter Show quoteHide quote > I want to set a property, that is an enum type, but I only have the > string available: > > Enum EggTypes > OverEasy > Scrambled > Poached > End Enum > Public myCookStyle as EggTypes > > Public Sub OrderEggs(Request as String) > 'Here is where I want to set the value of > 'myCookStyle based on the Request String > '... and NO I cannot change this code... > '(This code just demonstrates what I am doing.. I ONLY have the > string > 'or at BEST I have an integer that corosponds to the Integer value > 'of the EggType) > myCookStyle = ???? > End Sub > Thanks in Advance... >
Show quote
Hide quote
"Zorpiedoman" <nowherem***@beatles.com> schrieb: \\\>I want to set a property, that is an enum type, but I only have the string > available: > > Enum EggTypes > OverEasy > Scrambled > Poached > End Enum > > Public myCookStyle as EggTypes > > Public Sub OrderEggs(Request as String) > 'Here is where I want to set the value of > 'myCookStyle based on the Request String > '... and NO I cannot change this code... > '(This code just demonstrates what I am doing.. I ONLY have the string > 'or at BEST I have an integer that corosponds to the Integer value > 'of the EggType) > > myCookStyle = ???? > End Sub myCookStyle = _ DirectCast( _ [Enum].Parse(GetType(EggTypes), Request), _ EggTypes _ ) /// -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> |
|||||||||||||||||||||||