How To Use Answer Code Instead of Answer Index in Survey Scripts


Using answer codes when referencing an answer in the survey scripts is the best practice in many cases when scripting a survey.

Why?  When question answers change along the way, new answer might be added or the order of the existing answers might change -

The answer index will change but the answer code would remain the same (in case you have not changed the ‘lock answer automatic coding’ property - which means that you will not have to change your scripts when making those changes!

We have many functions that can be used in order to use answer codes instead of answer indexes when scripting here are a few common examples:

  • SelectedAnswerCode(int QuestionIndex)- returns the code of the answer selected in the QuestionIndex question.
  • GetAnswerChoiceIdxByCode(int inQuesIdx, string inAnswerCode) - Returns the answer index according to the matching answer code given.
  • AnswerCode(int inQuesIdx, int inAnswerIdx) - returns the answer code of an answer according to the given inAnswerIdx.


For more functions and information you can view our complete function library:


That's it!

Visit us at:


Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request


1 comment
  • Is it possible change answer index e.g
    3. Marital Status
    <1> Married
    <2> Living with a partner
    <3> Widowed
    <4> Divorced
    <5> Separated
    <6> Never married
    <8> Don't know
    <9> Refused

    <> repesenting the intended index

    Comment actions Permalink

Please sign in to leave a comment.