Answer.IterateValues Method

This method starts a recursive descent of the values for an answer. It visits each value for an answer and fires the Answer.OnValueFound event. In many cases, this saves you (the integrator) from iterating through combinations of repeat indices to find values in an answer tree.

Syntax

void IterateValues ( )

Example

The following Visual C# example opens an answer file and displays each answer it contains:

public class ExampleCode
{
    static string ansName;
    static string ansType;
     
    static void Main() 
    {
        HotDocs.AnswerCollection ac = new HotDocs.AnswerCollection();
        ac.Create(@"C:\Documents\HotDocs\Answers\AnswerFile.anx");
         
        Console.WriteLine("Variable\tAnswer\tType");
         
        foreach (HotDocs.Answer ans in ac)
        {
            ansName = ans.Name;
            ansType = getType(ans.Type);
            ans.OnValueFoundEvent += new HotDocs._AnswerEvents_OnValueFoundEventEventHandler(ans_OnValueFoundEvent); 
            ans.IterateValues(); 
        }
        Console.ReadKey();
         
        ac.Close();
    }
     
    static void ans_OnValueFoundEvent(object Value, int repeat1, int repeat2, int repeat3, int repeat4)
    {
        string index = ""; 
        string ansValue = ""; 
        if (repeat1 > -1) index = "[" + (repeat1 + 1).ToString() + "] ";
        //Check to see if the value is an array (multiple-select Multiple Choice variable)
        if (Value.GetType() == typeof(System.Object[]))
            foreach (string s in (System.Object[])Value)
            {
                ansValue += s + "; ";
            }
            else
                ansValue = Value.ToString();
              
            Console.WriteLine(index + ansName + "\t" + ansValue + "\t" + ansType);
    }
     
    static string getType(HotDocs.HDVARTYPE type)
    {
        switch (type)
        {
            case HotDocs.HDVARTYPE.HD_DATETYPE: 
                return "Date"; 
            case HotDocs.HDVARTYPE.HD_MULTCHOICETYPE: 
                return "Multiple Choice";
            case HotDocs.HDVARTYPE.HD_NUMBERTYPE: 
                return "Number"; 
            case HotDocs.HDVARTYPE.HD_TEXTTYPE: 
                return "Text"; 
            case HotDocs.HDVARTYPE.HD_TRUEFALSETYPE: 
                return "True/False"; 
            default:
                return type.ToString(); 
        }
    }
}