Creating dynamic buttons
By using scripts and calculations to evaluate the state of button fields, you can make dynamic buttons that change each time they are clicked.
To create dynamic buttons:
 •
 •
 •
The following example shows how to create a button that changes every time it is clicked.
To define the dynamic button field:
1.
Choose File menu > Manage > Database > Fields tab.
2.
3.
Click Create.
4.
Click Options > Storage tab.
5.
Select the Use global storage checkbox and type the number of button states for the Maximum number of repetitions, then click OK.
6.
7.
In Layout mode, add the Icons field to a layout.
8.
Click Inspector Inspector button in the layout bar, then click Data. For Show repetitions, display the maximum number of repetitions for the Icons field. See Setting up the display of repeating fields.
9.
10.
In Browse mode, select a repetition of the Icons field and choose Insert menu > Picture to add a graphic.
11.
Tip  Ensure that all graphics are the same size.
12.
13.
14.
Choose File menu > Manage > Database > Fields tab.
15.
Create a field named Buttons, choose Container type, then click Create.
16.
Click Options > Auto-Enter tab.
17.
Select Calculated value, then click Specify and enter the function GetRepetition (Icons; 1).
Tip  To create a button that displays identically across all records, click the Storage tab and select Use global storage. Otherwise, each record will display its own button state.
18.
Click OK, then OK again.
19.
Click OK.
20.
To create the dynamic button script:
1.
Choose Scripts menu > Script Workspace and click New script icon.
2.
3.
4.
For Specify target field, select the Buttons field.
5.
For Calculated result, write a Case function that evaluates each GetRepetition test expression for the icon number and increments the number by 1 (replacing the table name “icons” with the table in which you created the Icons field).
Note  This calculation assumes that the Icons field has five repetitions. Modify the calculation to match the number of repetitions you defined for the Icons field.
Case (
icons::Buttons = GetRepetition (icons::Icons; 1); GetRepetition (icons::Icons; 2);
icons::Buttons = GetRepetition (icons::Icons; 2); GetRepetition (icons::Icons; 3);
icons::Buttons = GetRepetition (icons::Icons; 3); GetRepetition (icons::Icons; 4);
icons::Buttons = GetRepetition (icons::Icons; 4); GetRepetition (icons::Icons; 5);
GetRepetition (icons::Icons; 1)
)
6.
To connect the field and the script:
1.
In Layout mode, select the Buttons field.
2.
Click Inspector Inspector button in the layout bar, then click Data.
3.
In the Behavior area, for Field entry, clear Browse Mode and Find Mode.
4.
Choose Format menu > Button Setup.
5.
For Action, choose Perform Script and specify Toggle Buttons.
6.
7.
For more information about using buttons with scripts, see Working with buttons and button bars on layouts.
Related topics 
Creating scripts to automate tasks
Working with formulas and functions