Dynamic constant name

I have a list of field names and constants for the corresponding field length that I would like to dynamically set the name for.

for example
i have const kCitylen =31

I can use select case if need be but was hoping not to have to add 20 or so cases
The idea is to display an edit box to allow interactive truncation
The problem portion is shown below

dim field_name as string = "City"
dim field_val as string = "Any City 1234567890123456789123456789"
dim const_name as string
const_name= "k" + field_name + "len"


create a dictionary instead. the names of constants , variables etc cannot be changed at runtime… that is a feature usually only found in an interpeted language.

the trick with constants and trying to look them up at runtime is that they dont actually retain their name

effectively everwhere you used a constant treat it like you have just swapped in the literal value

const kCitylen =31

dim i as integer = kCityLen

get treated like you wrote

const kCitylen =31
dim i as integer = 31

Those two are mutually exclusive. By definition a constant is, well, constant. When you need a dynamically set value, use something other than a constant. Such as the dictionary mentioned by Dave.