You will notice that variables are occasionally followed by a number or variable name in square brackets: Variable[2] or Variable[ NumVar ]. The rhyme and reason are explained here.
This issue only affects repeated variables (variables in repeated dialogs). Remember that a repeated variable can contain any number of answers. The "[x]" notation is simply a way of referencing a specific iteration of the repeated variable. For example, assume that the text variable Color has three answers: Red, Yellow, and Blue. If I use «Color[2]», the answer Yellow will be returned.
By the same token, if the number variable NumVar contains the value 3, then «Color[ NumVar ]» will return Blue.The difficulty is knowing when you need to use the square brackets and when you don't. Here's the key: If you are referencing a repeated variable inside of a REPEAT block (where its parent dialog is being repeated), you can omit the iteration reference (the square brackets). BUT,
If you are referencing a repeated variable outside of a REPEAT block, you must reference the desired iteration like this: Variable[ iteration number ]. Otherwise it will always return Variable[ 1 ]. AND,
If you are referencing a repeated variable within a foreign REPEAT block (meaning, a dialog other than its parent dialog is being repeated), you must reference the desired iteration. A good example is a computation that copies the answers from one REPEATed dialog to another. This example assumes DialogA which contains VariableA, and DialogB which contains VariableB:
// Copy the answers from DialogA to DialogB REPEAT DialogB SET VariableB TO VariableA[ COUNTER ] END REPEAT
The iteration of VariableA must be referenced explicitly, because it is not contained in DialogB. Clear as mud?
A Note on Format. HotDocs is very tolerant of whitespace. So all of the following usages are allowed:
Variable[1] Variable[ 1 ] Variable [1] Variable [ 1 ] Variable[NumVar] Variable[ NumVar ] Variable [NumVar] Variable [ NumVar ]