Reg Exp
Web Design
Notes Client
Check Constant
Last week we posted this tip about getting the string error message from a numeric error number. This tip is similar, but different. It will give you the numeric constant number from a string constant name. Why would you want to use this? I know that many developers out there use the constants. But there are also many of us (yes, I include myself) that never use the constants. MB_OKCANCEL? I use the value 1. But, when I'm looking in the help at a piece of LotusScript I either haven't used or haven't used in a long time, sometimes the help lists only the constant name and not the number. I don't want to bring in the whole LSS file just for one constant, so I wrote this little utility.
Please note... if you have purchased the Reusable Object Library Level 2 application, you can use the "Find New Reusable Objects" feature to quickly download this design element and it's associated documentation at no cost.
It's an agent that takes the name of a constant and gives you back the actual value. So, if you type in "MB_OKCANCEL", it will give you the value "1" in return. "RTELEM_TYPE_DOCLINK" will give you "5". And so on. Here's the code:

Dim GlobalConstant As Long
Sub Initialize
   Dim constant As String
   Dim script As String
   constant = Inputbox("Enter the constant you would like to evaluate", "Enter Constant", "")
   script = "GlobalConstant = " & constant
   Msgbox constant & " = " & Cstr(GlobalConstant), 64, "Constant"
End Sub

The code works by including the "LSCONST.LSS" file here - instead of in your big agent that needs one constant. It sets up a global variable to hold the value. You are then prompted for the name of the constant. Then some script is executed in-line that sets the global variable to the value of the constant. The code then can look at this global variable (that is the numeric value now, instead of the constant) and tells us (through a message box) the value of that constant.

So, if you're like me and use the numbers instead of the strings, when you see a new constant name in someone else's code, you can use this agent to find out the actual constant value when you reuse it in your own code.