﻿ Numerical conditions

# Numerical conditions

The + syntax should be used in preference to the obsolete ? form.

 • {+fieldname=['found'],['not_found'][[,initial_value],limit[,reset_value]]}

The + condition field syntax, when given numerical values, may be used to set up a number of counting functions. Full nesting of conditional field expressions is supported, e.g.
{field1*field2}
{field1*2-field2}
{field1}{field2}
etc. as long as they resolve to a number. {+fieldname=found,,[initial_value][,limit[,reset_value]]} A counter that is incremented when a named field is found.
 found, An integer specifying the number of characters to be used for a counter. If found value starts with a zero then leading zeros are inserted to make up the width, otherwise spaces are used. If the counter exceeds the specified width then it is not truncated and all digits are shown. Alternatively, a number of # characters would specify that number of characters be used for a counter. , This denotes a null value for the unused not_found parameter. initial_value (optional) The initial value used when the field is first evaluated, regardless of whether counting occurs or not. Omitting this parameter sets a null starting value. ,limit (optional) This is an integer value which specifies an ultimate value for a counter, after which the counter resets. ,reset_value (optional) The integer value to which the counter resets after the limit has been reached. If reset_value is omitted it defaults to initial_value. If initial_value is omitted it defaults to zero.

For example:

{+points=02,,03,12,01}

Initially, composite field is set to the value 03. Each time the field named "points" is found, the composite field value is incremented by 01 until it reaches the value 12. The next time "points" is found, the composite field value is reset to 01. {+fieldname=,not_found[,[initial_value],limit[,reset_value]]} A counter that is incremented when a named field is not found.
 , This shows that the (redundant) found parameter has been skipped and default value – null – set. not_found An integer specifying the number of characters to be used for a counter. If not_found value starts with a zero then leading zeros are inserted to make up the width, otherwise spaces are used. If the counter exceeds the specified width then it is not truncated and all digits are shown. Alternatively, a number of # characters would specify that number of characters be used for a counter. ,initial_value (optional) The initial value used when the field is first evaluated, regardless of whether counting occurs or not. Omitting this parameter sets a null starting value. ,limit (optional) This is an optional integer value which specifies an ultimate value for a counter, after which the counter resets to initial_value. ,reset_value (optional) The integer value to which the counter resets after the limit has been reached. If reset_value is omitted it defaults to initial_value. If initial_value is omitted it defaults to zero.

For example:

{+debit=,2,0} or
{+debit=,##,0}
Initially, composite field returns the value 0. Each time the field named "debit" is not found, the composite field value is incremented by 1. {+fieldname=found} A simple construct for counting found fields, where the initial value is null.
 found An integer specifying the number of characters to be used for a counter. Alternatively, a number of # characters would specify that number of characters be used for a counter.

For example:

{+count=1} or
{+count=#}
The composite field value starts null. Then each time the field named "count" is found, the composite field value is incremented by 1.

Obsolete syntax: {fieldname=digits[,initial_value[,limit]]} This initializes and increments a counter: use +fieldname syntax above instead.
 fieldname= The composite value must include a field name followed by an equals sign. digits Specifies how many characters wide the 'counter' field should be. It may be an integer or a string of # characters. ,initial_value (optional) The value that the counter starts counting from. Default value is zero. ,limit (optional) Ultimate value that the counter can reach before resetting to initial_value.

When the specified field is encountered for the first time, the counter is set to initial_value, or 0 if that is not specified. Subsequently, if the field exists the counter is incremented until it reaches the limit (if any), when it is reset to the initial value.

If digits parameter value is an integer and starts with a zero then leading zeros are inserted to make up the width, otherwise spaces are used. If digits parameter value is a number 'n' of # characters, then the width is specified as n characters.

If the counter exceeds the specified width then it is not truncated and all digits are shown.

Examples:

Invoice {page1=1,1}
This specification would have the value "Invoice 1" the first time field page1 was found, and the number would increment each time field page1 was found.

Set{page1=02,0,99}
This specification would start at "Set00" and go up to "Set99" before resetting to "Set00".

To truncate the counter another composite field may be used. For example, you might use:
{countfield:-4}
to take the last 4 digits of countfield.

See also More on defining composite fields.