Programming the repeat loop

Hi,

I have to pick up the count of boys and girls in classes 1 to 10.

A bad way of doing is that I have created a group with one label saying CLASS 1, and then 2 text-inputs saying to enter total number of boys and girls in that class (class 1 in this case). Then I am copy-pasting the same group 10 times and changing the class number + count variables to new class number. But this is bad programming, I know!

I need some help in putting the one group I create into a repeat loop, and modifying label as well as count variable names according to the class number for that loop. I can modify the label, but how to change the variable names to reflect class number w.r.t the repeat loop count?

An example would be great.

Many thanks,
Saad

A repeat group will send the data to a second table. In the below case you would have your submission table and then your class_repeat table. For each row in your submission table, you would have 10 rows in your class_repeat table.

Does this help you?
class_repeat.xlsx (8.8 KB)

+--------------+--------------+---------------+----------------------------------+--------------+
|     type     |     name     |     label     |           calculation            | repeat_count |
+--------------+--------------+---------------+----------------------------------+--------------+
| begin_repeat | class_repeat |               |                                  |           10 |
| calculate    | class_number |               | position(..)                     |              |
| calculate    | class_name   |               | concat("Class ",${class_number}) |              |
| note         | my_note      | ${class_name} |                                  |              |
| end_repeat   |              |               |                                  |              |
+--------------+--------------+---------------+----------------------------------+--------------+

This seems the logical solution. However, when I put in a text type element and try to set its name to any of the variables calculated above, the compiling does not go happy!

Error: [row : 33] Invalid question name [${class_name}] Names must begin with a letter, colon, or underscore.Subsequent characters can include numbers, dashes, and periods.

Am I missing something?

OK I guess I got the point. There is no need for different variable names, since it is not into flat hierarchy and looped data is going into a separate group.

Are you trying to reference data on one of the classes (from inside one of the repeat groups) outside of the repeat group (that is, later in the form)? For that you will need to follow this: https://docs.getodk.org/form-repeats/#referencing-repeated-questions-from-outside-the-repeat

If you are still having trouble with your form, are you able to attach it here? Or send it via direct message?