Is it possible to read constants programatically

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.

Any ideas?

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.

Subject: is it possible to read constants programatically

Maybe you could use the List object class.

Example:

Dim ErrorCodesList List As String

ErrorCodesList(4403) = “NO DATABASE”

ErrorCodesList(4404) = “DB CREATE ERROR”

ErrorCodesList(4405) = “NO DOCUMENT”

Messagebox ErrorCodesList(code)

Subject: RE: is it possible to read constants programatically

Excellent solution! Thanks.

Subject: I would recommend raising your own errors using the Error statement

This allows you to specify your own error code and message, and have the error handled by your existing error handling code.