Stylesheet Development with APP > Adding APP Code to Stylesheet Source > Samples > Counters and Variables > Use APP Counters and Variables
  
Use APP Counters and Variables
Samples directory: Arbortext-path/samples/APP/CountersAndVariables
Sample file: countersAndVariables.xml
Main stylesheet: countersAndVariables.style
Stylesheet modules: baseStylesheet.style and countersAndVariablesPropertySets.style
The sample is based on the standard axdocbook document type. It demonstrates how to set, increment, display, and reset the values of counters and variables.
Some information about APP’s counters and variables is given below:
Numeric counters
A numeric counter increments by a specified number every time an element that references it is encountered within a particular scope. The current value of a counter can be manipulated or tested at any point in a document to provide context-specific formatting. You may also choose to simply display its value.
In traditional APP syntax, numeric counters are called x counters. They can be accessed via APP's original show string mechanism using the syntax x(), where the number in parentheses indicates which counter slot is being used. APP has 200 numeric counter slots available, the first 10 being reserved for use by Arbortext Styler. Within an Arbortext Styler stylesheet, the counters are accessed via the counters property of the fFormatting object. This property is an array of integers.
Numeric counters (x counters) are described as format safe. APP will remember their values inline with the formatting process. Page up and down actions will have no effect on their value.
String counters
A string counter allows users to store a text string of up to 3500 characters in length (approx). The current value of a string counter can be manipulated or tested at any point in a document to provide context-specific formatting. You may also choose to simply display its value.
APP has 100 string counters available, but as with numeric counters the first 10 are reserved for use by Arbortext Styler. Within an Arbortext Styler stylesheet, the counters are accessed via the stringCounters property of the fFormatting object. This property is an array of strings.
String counters are described as format safe. APP will remember their values inline with the formatting process. Page up and down actions will have no effect on their value.
Global variables
APP works with two types of global variable:
1. Variables that are created and managed by JavaScript
2. Variables that are managed by APP itself
The samples deal with APP’s own global variables.
You may create any number of global variables in APP and name them as required. Within an Arbortext Styler stylesheet, APP global variables are accessed via the variables property of the fApplication object. This property is an array of scalar system variables.
JavaScript variables are format safe, whereas properties on objects are not.