Constant examples

The following examples show how constants can be used in an application.

Example 1

The following constant represents the number of payments in a year.

[spacer]

Constant Name

ANNUAL_PAYMENTS

Constant Value

12


The following script uses the constant to calculate the amount of the monthly payment.

'Monthly Payment' = 'Total Cost' / ANNUAL_PAYMENTS;

The constant is used the same way its value would be, with the advantage that the constant name is easy to remember.

Example 2

The following constant represents a specific style of house. The constant is defined for the Houses form.

[spacer]

Constant Name

BUNGALOW

Constant Value

2


The following script is part of the Buyers form. It uses the constant from the Houses form to set house type. Notice that the qualifier of form form_name is used to indicate where the constant is defined.

'Type' of window Buyers = BUNGALOW of form Houses;

Example 3

The following example shows how the ASKBUTTON constants are used with the ask() function to display a message in a dialog box. The ASKBUTTON constants are always used in conjunction with the ask() function.

The ask() function returns the appropriate ASKBUTTON value, corresponding to the button the user clicks. The if then...end if statement is used to ascertain which button was clicked so the appropriate action can be taken.

local integer Choice;

Choice = ask("Which option do you want?", "First","Second","Third");
if Choice = ASKBUTTON1 then
	run script First_Choice;
elseif Choice = ASKBUTTON2 then
	run script Second_Choice;
else 
	run script Third_Choice;
end if;

 


Documentation Feedback