Ennumerate definution


Author
Message
Ian Johnston
Ian Johnston
StrataFrame User (151 reputation)StrataFrame User (151 reputation)StrataFrame User (151 reputation)StrataFrame User (151 reputation)StrataFrame User (151 reputation)StrataFrame User (151 reputation)StrataFrame User (151 reputation)StrataFrame User (151 reputation)StrataFrame User (151 reputation)
Group: StrataFrame Users
Posts: 77, Visits: 470
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?


Charles R Hankey
Charles R Hankey
Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)
Group: Forum Members
Posts: 524, Visits: 30K
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.





Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.3K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
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!
Ian Johnston
Ian Johnston
StrataFrame User (151 reputation)StrataFrame User (151 reputation)StrataFrame User (151 reputation)StrataFrame User (151 reputation)StrataFrame User (151 reputation)StrataFrame User (151 reputation)StrataFrame User (151 reputation)StrataFrame User (151 reputation)StrataFrame User (151 reputation)
Group: StrataFrame Users
Posts: 77, Visits: 470
Thanks both of You, went the table route.
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.3K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Glad you got it going!
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search