How to get constant value from string

Probably a newbie question.
I have a series of constant values (as string) in a popupmenu. These constants are related to integer value.
How I can get back the integer value from the string which is returned by the PopupMenu.text?
The way I’ve founded, works but is not elegant.

dim temp as string
dim ColorS as integer
      select case temp
      case "CV_HSV2RGB" 
        ColorS= CV_HSV2RGB
      case "CV_HSV2BGR"
        ColorS= CV_HSV2BGR
      case "CV_BGR2HLS"
        ColorS= CV_BGR2HLS
      case "CV_RGB2HLS"
        ColorS= CV_RGB2HLS
      case "CV_HLS2BGR"
        ColorS= CV_HLS2BGR
      case "CV_HLS2RGB"
        ColorS= CV_HLS2RGB
      case "CV_BGR2Lab"
        ColorS= CV_BGR2Lab
      case "CV_RGB2Lab"
        ColorS= CV_RGB2Lab
      case "CV_Lab2BGR"
        ColorS= CV_Lab2BGR
      case "CV_Lab2RGB"
        ColorS= CV_Lab2RGB
      case "CV_BGR2Luv"
        ColorS= CV_BGR2Luv
      case "CV_RGB2Luv"
        ColorS= CV_RGB2Luv
      case "CV_Luv2BGR"
        ColorS= CV_Luv2BGR
      case "CV_Luv2RGB"
        ColorS= CV_Luv2RGB
      end Select

In other language such as Rebol or Red some instruction similar to colorS: get to word! face/text, gives a direct access to the value of the constant.
BTW, in the popupmenu we can use #constant name but after compilation the name of the constant is replaced by the value (e.g. CV_HSV2RGB is replaced by 54) , which is correct but not convenient for user!
Thanks a lot.

look at the DICTIONARY object in the Lang Ref

I assume that the constants are more than “0, 1, 2, 3, …”, or ListIndex is all you’d need.

Use the PopupMenu RowTag method to assign the value to each row.

pum.AddRow "CV_HSV2RGB"
pum.RowTag( 0 ) = CV_HSV2RGB

You can create a custom method to make this easier, but if you don’t need the constants anywhere else, I’d do this differently. Set up a single constant with a string value like this (making up the values, obviously):


Set up the popup menu with code like this:

dim items() as string = kPopupValue.Split( EndOfLine )
for itemIndex as integer = 0 to items.Ubound
  dim parts() as string = items( itemIndex ).Split( "," )
  pum.AddRow parts( 0 ).Trim
  pum.RowTag( itemIndex ) = val( parts( 1 ).Trim )
next itemIndex

Later, you can get the value like this:

ColorS = pum.RowTag( pum.ListIndex )

I should mention that this is off the top of my head so forgive any typos, etc.

Thanks a lot
Very smart solution