Answer.RepeatCount Property

[Read-only] This property returns the number of repetitions of the Answer at the current level. For example, if a non-nested answer is repeated three times, this property would return 3. If a nested answer is repeated 4 times at the first iteration and 2 times at the next, this property would return either 4 or 2 depending on the current repeat indexes.

Syntax

public int RepeatCount { get; }

Example

The following Visual C# code opens an answer file, iterates through its AnswerCollection, and displays each Answer and its Values. After each value, it also displays the RepeatCount at the current level.

public class ExampleCode
{
    static void Main()
    {
        HotDocs.Server.AnswerCollection ac = new HotDocs.Server.AnswerCollection("c:\\temp\\JohnDoe.anx");
         
        foreach (HotDocs.Server.Answer ans in ac)
        {
            System.Console.WriteLine(ans.Name);
             
            // Iterate through each of the Answer's Values.
            int[,] myArray = ans.ValueIndexes;
            for (int i = 0; i < myArray.GetLength(0); i++)
            {
                ans.RepeatIndexes[0] = myArray[i, 0];
                ans.RepeatIndexes[1] = myArray[i, 1];
                ans.RepeatIndexes[2] = myArray[i, 2];
                ans.RepeatIndexes[3] = myArray[i, 3];
                 
                System.Console.Write("{0},{1},{2},{3}: ", ans.RepeatIndexes[0].ToString(), ans.RepeatIndexes[1].ToString(),
                ans.RepeatIndexes[2].ToString(), ans.RepeatIndexes[3].ToString());
                 
                if (ans.Value.GetType().IsArray)
                {
                    // This means the value is an array, such as a "select all that apply" Multiple Choice value.
                    System.Object[] valArray = (System.Object[])ans.Value;
                     
                    for (int j = 0; j < valArray.GetLength(0); j++)
                    {
                        System.Console.Write(valArray[j].ToString());
                        if (j < (valArray.GetLength(0) - 1)) System.Console.Write("|");
                    }
                }
                else System.Console.Write(ans.Value.ToString());
                System.Console.WriteLine(" (RepeatCount: " + ans.RepeatCount + ")");
            }
        }
        System.Console.ReadKey();
    }
}