This look correct, yes. Please give it some tests in the debug mode and maybe add debug($nQnr);
and debug($nMax);
at the end to observer what the PHP code does (in the debug information) and see that everything works. In testing mode all records are counted by statistic()
, while in the real interview, only MODE=interview records are counted. To testing is no problem for your stats.
$Res
is simply a variable to store value('CO04')
temporarily. You could as well write value('CO04')
instead of $Res
every time, but that would be longer (and less efficient).
Just a warning: Your counter will as well count those cases that were screened out after a quota full. Because redirect()
will set FINISHED=1. This is no problem for your quota check, as long as you don't need cross-variable quotas and you don't have to raise the quota after it was reached. If you anticipate you'll need either of that, than copy CO04 to an internval variable at the end of the questionnaire, and count that internal variable instead CO04 in statistic()
.