StrataFrame Forum

Ennumerate definution

http://forum.strataframe.net/Topic27411.aspx

By Ian Johnston - 6/12/2010

I am trying to build an enum of baud rates to populate a drop down list.

public enum BaudRateVal

{

1200,

2400,

4800,

9600,

19200,

38400,

57600,

115200,

230400

}

Gives an error "Identifier expected", what is missing?

By Charles R Hankey - 6/13/2010

Since an enum is itself an integer it is not going to accept and integer as a "string"



It will accept



Baud1200

Baud2400

etc



but doesn't seem to like



1200Baud

2400Baud



etc.



You probably would be better off just creating a dropdownlist combobox and explicitly filling in the items collection.



Seems you'd be better off storing the baud rate as string anyway. Kind of like a phone or zipcode - all numbers but not really used that way.




By Greg McGuffey - 6/14/2010

As Charles has stated, in C#, an identifier must start with either a letter or an underscore. So, you have some options:



1. Use an enum, change name to something like "Baud1200" or "_1200".

2. Use enum, name as above but add the EnumDisplayValue attribute to the enum items to explicitly provide the display value. This is in MicroFour.StrataFrame.Tools namespace.



using MicroFour.StataFrame.Tools;

public enum BaudRateVal

{

  [EnumDisplayValue("1200")]

  Baud1200,



  [EnumDisplayValue("2400")]

  Baud2400,



  [EnumDisplayValue("4800")]

  Baud4800,



  [EnumDisplayValue("9600")]

  Baud9600,



  [EnumDisplayValue("19200")]

  Baud19200,



  [EnumDisplayValue("38400")]

  Baud38400,



  [EnumDisplayValue("57600")]

  Baud57600,



  [EnumDisplayValue("115200")]

  Baud115200,



  [EnumDisplayValue("230400")]

  Baud230400

}




3. Add a table with the Baud rates, then fill the combo with a BO instead of an enum.



Hope that helped!
By Ian Johnston - 6/14/2010

Thanks both of You, went the table route.
By Greg McGuffey - 6/14/2010

Glad you got it going!