# CalcBuilder Forum

#### Code for Multiple Option Matrix

User KYG 2016-01-02 21:06:15

Hello- I am trying to write the code to calculate two variables after the user selects from 3 option fields.

When the user selects from>>>

OPTION 1
OPTION 2
OPTION 3

Then when they press calculate, then I want it to display VARIABLE 1 and VARIABLE 2.

I have this set up in a matrix with the following columns.
OPTION 1, OPTION 2, OPTION 3, VARIABLE 1, VARIABLE 2

Screen Shots can be sent if you give me an email address.

Thanks!!!!

Moonsoft support 2016-01-03 11:42:08

Hello,
if we've understood properly, you have two values returned for each combination of the 3 values of your option fields. If you build the matrix with separated column, you will have to loop over all rows of the matrix to check if the combination matches and then return the value. It's a valid solution, but we can suggest another structure to recover the values with a single line of code, the approach is to build the matrix using as first column (the key) the combination of the values:

(Key column) VARIABLE1 VARIABLE2

o11#o21#o31 result1 result2
o12#o22#o32 result3 result4
o13....

being o1x the different values for option1, o2x values for option2...etc

now at the code, you could use the key to return both values, if your matrix is called,for ex, 'resultmatrix':

\$key=\$option1."#".\$option2."#".\$option3;

\$value1=\$resultmatrix;
\$value2=\$resultmatrix;

If you need further help, you can attach screenshots and we can share code at the helpdesk.

Regards

Edited by MSTeam - 03.01.2016 11:43

##### Support/development 10 hours

Get a bigger amount of hours for more complex tasks and get a 10% discount

##### List Manager

Build different lists for your site