# Logic check with 2 grid number

Q1 Select format (Multiple answers), there are 300 brands:
Brand1
Brand2
Brand3
....
Brand300

Q2 Grid Numer , there are 300 rows and 3 columns.

I have created construction list for Q2 like this => AIC(Q1)

Column 1        |        Column 2           |       Column 3
Q2Row1 -    Input Number   |    Input Number    |   Input Number
Q2Row2 -    Input Number   |    Input Number    |   Input Number
Q2Row3 -    Input Number   |    Input Number    |   Input Number
.....
Q2Row300 -    Input Number   |    Input Number    |   Input Number

Q3 Grid Numer , there are 300 rows and 3 columns.

I have created construction list for Q3 like this => AIC(Q1)

Column 1        |        Column 2           |       Column 3
Q3Row1 -    Input Number   |    Input Number    |   Input Number
Q3Row2 -    Input Number   |    Input Number    |   Input Number
Q3Row3 -    Input Number   |    Input Number    |   Input Number
.....
Q3Row300 -    Input Number   |    Input Number    |   Input Number

Here the logic check and show error message:

If Q2Row1Col1 > 0 and  Q3Row1Col1 = 0 => Error message
If Q2Row1Col1 = 0 and  Q3Row1Col1 > 0 => Error message
If Q2Row1Col2 > 0 and  Q3Row1Col2 = 0 => Error message
If Q2Row1Col2 = 0 and  Q3Row1Col2 > 0 => Error message
If Q2Row1Col3 > 0 and  Q3Row1Col3 = 0 => Error message
If Q2Row1Col3 = 0 and  Q3Row1Col3> 0 => Error message
.......
.......
If Q2Row300Col3 > 0 and  Q3Row300Col3 = 0 => Error message
If Q2Row300Col3 = 0 and  Q3Row300Col3 > 0 => Error message

Is it possible? and how can i fix this?
asked Jan 26, 2018
retagged Jan 26, 2018

+1 vote

Give this a shot:

```var q2Resps = [% Begin Unverified Perl
my \$out = '[';
my \$sep1 = '';
for (my \$r = 1; \$r <= 300; \$r++) {
\$out .= \$sep1 . '[';
\$sep1 = ',';
my \$sep2 = '';
for (my \$c = 1; \$c <= 3; \$c++) {
\$out .= \$sep2 . '"' . GETVALUE('Q2_r' . \$r . '_c' . \$c) . '"';
\$sep2 = ',';
}
\$out .= ']';
}
\$out .= '];';
return \$out;
End Unverified %]

for (var r = 1; r <= 300 && !strErrorMessage; r++) {
for (var c = 1; c <= 3 && !strErrorMessage; c++) {
var q2NonZero = Number(q2Resps[r - 1][c - 1]) > 0;
var q3NonZero = Number(SSI_GetValue('Q3_r' + r + '_c' + c)) > 0;
if ((q2NonZero && !q3NonZero) || (q3NonZero && !q2NonZero)) {
strErrorMessage = 'Error';
}
}
}
```
answered Jan 26, 2018 by Platinum (97,550 points)
selected Jan 27, 2018 by Saroeun
Thanks, Zachary

I want to know which row error. Could you add more script?
Update line 23.

```strErrorMessage = 'Error on row ' + r;
```
I want to change:
If Q2Row1Col1 > 0 and  Q3Row1Col2 = 0 => Error message
If Q2Row1Col1 = 0 and  Q3Row1Col2 > 0 => Error message
If Q2Row1Col2 > 0 and  Q3Row1Col3 = 0 => Error message
If Q2Row1Col2 = 0 and  Q3Row1Col3 > 0 => Error message
If Q2Row1Col3 > 0 and  Q3Row1Col4 = 0 => Error message
If Q2Row1Col3 = 0 and  Q3Row1Col4> 0 => Error message
.......
.......
If Q2Row300Col3 .......
If Q2Row300Col3 .......

Is it possible?
Lines 20 and 21 show you how to get the Q2 and Q3 responses:

```var q2 = Number(q2Resps[r - 1][c - 1]);
var q3 = Number(SSI_GetValue('Q3_r' + r + '_c' + c));
```

Can you modify line 22's if statement so that it checks if one of the values is zero and the other not?