Constants are fixed numeric or string values that are used in scripts, where the constant name is used in place of the value associated with it. Two types of constants are available in Dexterity: Dexterity constants and user-defined constants.
Dexterity has a number of predefined constants that can be used in scripts. For example, the three constants listed in the following table are used with the ask() function.
Constant name |
Description |
---|---|
ASKBUTTON1 |
The value returned from the ask() function when the first button is clicked in the ask dialog box. |
ASKBUTTON2 |
The value returned from the ask() function when the second button is clicked in the ask dialog box. |
ASKBUTTON3 |
The value returned from the ask() function when the third button is clicked in the ask dialog box. |
In the following example, the ask() function uses predefined constants to determine which button the user clicked.
if ask("Include sales tax?","Yes","No") = ASKBUTTON1 then Total = Total + Tax; end if;
You can also create your own constants using the Constant Definition window. For example, you could define a constant named “PAY_PERIODS” to have the value 24, representing the number of pay periods in a year. To calculate an employee’s salary in a script, you can use the constant in place of the number.
'Check Amount' = Salary / PAY_PERIODS;
You can define global constants or form-level constants. Global constants can be accessed by any script in your application. You should use them when you anticipate a constant will be used by scripts throughout the application.
Form-level constants are designed to be used by a specific form in the application. You should use them when several scripts on a form use a constant, but there is little need to use the constant elsewhere in the application.
Within the scope of a form, you can reference a form-level constant directly. To reference a form-level constant from outside the scope of a form, use the qualifier of form form_name. If a form-level constant and a global constant have the same name, by default, scripts attached to the form will use the form-level constant. To refer to the global constant instead, use the qualifier of globals following the name of the constant. For example, the following statement refers to the BUNGALOW constant defined on the Houses form.
'Type' of window Buyers = BUNGALOW of form Houses;