How to avoid creating multiple variables that perform the same calculation logic?

Hello Survey Solutions Team.

I would like to know how I can avoid creating multiple variables that perform exactly the same operation but in different sections.

For example, I have a form with 22 sections (see the imagen)

The variable have the operation aritmethic MainVariable:
RosterSections.Select(x=> (x.ProductValue??0) - (x.HelpReceived??0)).ToArray()[@rowcode-1]

The last explication create an array like this:
[ValueSection1, ValueSection2, ValueSection3, ValueSection4,...,ValueSection22]

But if I want to access at the value of each section I should to create each variable for each item in the array.
Like this way
ValueInSection1 = RosterSections.Select(x=> x.MainVariable).ToArray()[0] ValueInSection2 = RosterSections.Select(x=> x.MainVariable).ToArray()[1] . . . ValueInSection22 = RosterSections.Select(x=> x.MainVariable).ToArray()[21]

But I would like to know an optimal and more efficient way to do this.

Thanks for help me.

1 Like

Hello Kevin,

my sense is that you wish to display them as separate values in the screen report/summary section. Hence they must be calculated and stored as separate variables, that would be later accessible in text substitution %varname%.

You could probably simplify the notation with a macro:

ValueInSection22 = $sections[21]

where $sections is defined as:

RosterSections.Select(x=> x.MainVariable).ToArray()

This will reduce the possibility of a typo and will ease subsequent transformations, but wont give any computational gain.

Best, Sergiy

1 Like

Hello Sergiy

Exactly that is my intention, display them as separate values.

Fantastic, yesterday I built a macro like this, each section stores its value in a specific position of the array.

Thanks Sergiy, your help is very valuable in our project

1 Like