How do I set an answer with the sum of the answers of two other numeric questions

Hi,

I wish to calculate a total of two numeric questions. This total needs to be saved in the data. How would one do this?

Marinus Koekemoer

--------------------------------------------------------------------------------------------------------------------------------------------------------------

Hi Marinus,
To do this, simply add an expression type question and in the answers write:

var sum = Answer(xx).ToInt() + Answer(yy).ToInt();
return sum;

this will then save the sum of the answers in the expression question.
Alternatively you can also do the following (it is almost the same):
1. Add a numeric question and mark it as hidden (advanced > hidden from surveyor = true)
2. Then in the end script of the question before this question (not the numeric question itself) write:
SetAnswer(xx, Answer(yy).ToInt() + Answer(zz).ToInt());

Where xx is the numeric question index and yy/zz are the questions to be summed.
The 2 methods are both good. the first one is a bit easier to implement.
Regards,
Dooblo Support

0

Comments

0 comments

Please sign in to leave a comment.

Didn't find what you were looking for?

New post