Creating an enum

This is probablly very easy, but I am not sure what’s the best way to achieve it… fast…

I need to create a country list, with a certain code for each country and then let the user choose from a list… (and of course get the asociated code)

I been given a list with this format : XXX_COUNTRYNAME

What would be the easiest way ?


Paste your list into a constant. When your app starts, parse the list into a Dictionary where the key is the country name. When your user chooses from the list, lookup their choice in the Dictionary.

If they will be choosing from a popup menu, you can create a CountryPopupMenu subclass that does this work for you so you can reuse it easily.

I thought I would create an array first, to iterate thru it and create one dictionary entry for each country… But I am failing in this line…

dim CountryList() as string = Split(app.Countries, EndOfLine)

It only detects ONE line… although every line has an endofline at the end… I’m sure…

done… replaced EOF for Chr(13)

Errr, not the most reliable way to do that.
Given your code from the post above:

dim sSanitizedCountryString as String = ReplaceLineEndings(App.Countries, EndOfLine)
dim arsCountryList() as String = Split(sSanitizedCountryString, EndOfLine)

The ReplaceLineEndings function accounts for and fixes line endings from whatever system put them there.

Got it working… thanks a lot guys !