top of page

02. Count how often a Multiple Choice answer was selected

Description

Counts how many times each option of a MC variable was selected in a REPEAT.

Code

""
SET Option1-n TO 0
SET Option2-n TO 0
SET Option3-n TO 0

REPEAT RepeatedDialog
IF MultipleChoice-m = "Option 1"
SET Option1-n TO Option1-n + 1
ELSE IF MultipleChoice-m = "Option 2"
SET Option2-n TO Option2-n + 1
ELSE IF MultipleChoice-m = "Option 3"
SET Option3-n TO Option3-n + 1
END IF
END REPEAT

Explanation

The computation requires one Number variable for each option of the Multiple Choice variable (Option1-n, Option2-n, etc.).

The computation variable walks through the REPEAT, incrementing each of the number variables as their option is chosen. Then finding out how many times a given option was selected is as simple as looking at the value for the corresponding number variable.

bottom of page