A variable is a name associated with a value (data). A value is stored in a variable and that variable contains the value. Variables allow you to store and manipulate data in your models.
What makes variables useful is that the value or data they contain can be changed or set during the execution of a model. For example, your model contains a calculation, of which the result must be put in several places of the result document. A variable of type NUMBER can contain the result and everywhere the result is needed in the model the variable is inserted. You can use the construction @(variable) to present the value of a variable in the result document.
Or; you want to list and number all customers in a result document. A variable can be used to increment the total amount of customers for every customer that is put in the result document.
Variables can also be used to contain values from a database. For instance the database has a field that contains Mister for men and Miss for women. When this field determines the value of a variable all you have to do in the model is put that variable where you want Miss or Mister to appear in the result document. In this case also, the construction @(variable) will place the value of the variable in the result document. This is especially useful if a value is needed more than once in the model.
A variable must be declared before it can be used. A variable is declared with stating its data type (BOOL, TEXT or NUMBER), its name and an optional initial value.
A valid variable name:
Example
BOOL contribution_payed
NUMBER rate
TEXT his_her
A variable can be declared where you need it in a model. However, a variable has a scope. A variable is available from the point of declaration downwards in the model to the point where the code block ends. If Include documents are called after the point of declaration the variable is available in them as well. Variables declared within constructions or blocks are restricted to that block.
Blocks in ITP are between:
There is also model scope; if a variable is declared outside a block at the start of the model, it will have a global scope and it can be used in all blocks within the model.
The declaration of a variable can be combined with the assignment of an initial value to that variable.
TYPE variable := value
Example
BOOL contribution_payed := TRUE
NUMBER rate := 78
TEXT his_hers := "his"
If a variable has been declared but no initial value has been assigned to it the following applies;
A variable can be assigned a value. If a variable already contains a value this value will be replaced with the new value.
ASSIGN name_of_the_variable := value
Example
ASSIGN his_her := "his"
Word processor instructions can be assigned to a variable of the type TEXT, e.g., to store a paragraph break or a tab in a variable.
Example
#BEGIN
TEXT new_paragraph
ASSIGN new_paragraph := "
"
#
This is the first paragraph. @(new_paragraph)This is the second paragraph.
#
END#
Result:
This is the first paragraph.
This is the second paragraph.
You can store styles in variables through paragraph symbols, which Microsoft Word uses to store styles that are used in a paragraph.
Example, assigning the style heading to a variable.
#BEGIN
TEXT heading_paragraph
ASSIGN heading_paragraph := "
"
#
This is the first paragraph. @(heading_paragraph)This is the second paragraph.
#
END#
Result:
This is the first paragraph.
This is the second paragraph.
Note the style of the above statement and it is a Microsoft Word style and not character lay-
ut. It is this style that is attached to the paragraph sign stored in the
heading_paragraph variable.
Note in the result below that the first paragraph indeed received the style attached
o the paragraph sign stored in the heading_paragraph variable.
To prevent that a style assigned to a fragment of a paragraph is considered to be a character style, the style is assigned to the complete variable assignment paragraph. If you encounter problems with style assignment through a variable, the cause will almost always be that the style is interpreted as a character style by Microsoft Word. You can use Shift-F1 to call the Microsoft Word Help. In this Help, information is presented on the styles used in the paragraph of the location of your cursor.
Note
Do not use . Paragraph ends in a table are specific objects. If you want to store such a paragraph end in a table in a variable, it must also be declared as a paragraph end within the table.
An assignment of a value to a variable can be combined with an operation to add or subtract a value from the value already stored in the variable. These operators that can be used are: +, -, *, / and %.
ASSIGN name_of_variable +:= formula
ASSIGN name_of_variable -:= formula
ASSIGN name_of_variable *:= formula
ASSIGN name_of_variable /:= formula
ASSIGN name_of_variable %:= formula
Examples
ASSIGN rate - := 12
ASSIGN name + := "mister"
These combined assignments establish the same as the following normal assignments:
ASSIGN rate := rate - 12
ASSIGN name := name + "mister"
@( name_of_variable )
Example
@( his_hers)
The content of the variable his_hers is placed in the text.