top of page

80. Sum a Filtered Dialog

Description

How to sum a number field from a filtered repeating dialog.

Code

0
REPEAT RepeatedDialog
FILTER FilterComputation-c
RESULT + NumVar
END REPEAT


Alternative:

0
REPEAT RepeatedDialog
IF IncludeInTotal-b = TRUE
RESULT + NumVar
END IF
END REPEAT

Explanation

A filtered dialog can be summed by adding the number variable manually. The first code example shows a repeated dialog that has been filtered with FilterComputation-c, a TRUE/FALSE computation. The dialog contains a number variable, NumVar, which is the variable to be summed. The computation is initially set to the value of 0, then the value of NumVar is added to the result with each pass of the REPEAT. The total will be returned by the computation.

The alternative code uses IF logic rather than a filter, but reaches the same result. This example assumes that there is a true/false variable on the dialog called IncludeInTotal-b. If this variable is checked, that iteration of the repeated dialog will be included in the sum. The script starts at a value of 0, then adds NumVar to the total only if IncludeInTotal-b is TRUE. The total is returned by the computation.

bottom of page