I have an application with a module that can return a range of error codes. I would like to be able to turn these codes into meaningful text messages, and I use Constants, like this:
Public Const ERR_UI_4402 = “NO WORKSPACE”
Public Const ERR_UI_4403 = “NO DATABASE”
Public Const ERR_UI_4404 = “DB CREATE ERROR”
Public Const ERR_UI_4405 = “NO DOCUMENT”
What I would like to do is to be able to get the translation from code to text programatically, not have to test each code like this:
If code = 4404 then Messagebox ERR_UI_4404
If code = 4405 then Messagebox ERR_UI_4405 etc.
This needs something equivalent to a FieldGetText command, but these are not field values.
Subject: is it possible to read constants programatically
Just an explanation of why it can’t work the way you had envisioned:
Constant values actually replace their names (placeholders) at compile time, so your statement:
If code = 4404 then Messagebox ERR_UI_4404
compiles as if you had typed:
If code = 4404 then Messagebox “DB CREATE ERROR”
in the first place. That’s why it’s legal to put constants in the Options slot – they’re not code as much as they are directives to the compiler. That is quite different from a variable, which is nothing more than a handy named reference to a memory location that exists at run time.