How to parse commas within a List BoxHello,
I am on JMP 18.1.2 and am attempting to create a matrix of check boxes. The final step which I cannot figure out, is how to dynamically create the H List Box based on number of rows.
This is my current code:
test = {"a","b","c","d","e"};
testFin = {};
rows = 2;
remain = Modulo(N Items(test), rows);
loops = 2 + (remain > 0);
//create a list that groups the original list in groups of 2 (rows)
for(i=1, i<= loops, i++,
test2 = {};
if(i != loops,
for(j = 1, j<= rows, j++,
test2[j] = test[1];
test = remove(test,1);
);
,
for(j = 1, j<= remain, j++,
test2[j] = test[1];
test = remove(test,1);
);
);
testFin[i] = test2;
);
//testFin = {{"a", "b"}, {"c", "d"}, {"e"}}
cb = {};
cancel_check = 0;
ttp = "";
for(i = 1, i<= N Items(testFin), i++,
if(i != N Items(testFin),
ttp ||= "cb["||Char(i)||"] = Check Box(testFin["||Char(i)||"]), \!n"
,
ttp ||= "cb["||Char(i)||"] = Check Box(testFin["||Char(i)||"]);"
);
);
/*ttp = "cb[1] = Check Box(testFin[1]),
cb[2] = Check Box(testFin[2]),
cb[3] = Check Box(testFin[3]);"*/
testw = new window("raaa", <<MODAL></MODAL>
The error I get when trying to run it is:
Unexpected ",". Perhaps there is a missing ";" or ",".
Line 1 Column 30: cb[1] = Check Box(testFin[1])►,
The remaining text that was ignored was
,cb[2]=Check Box(testFin[2]),cb[3]=Check Box(testFin[3]);
The desired output (if I just replaced the parse with what ttp is and ran it) is attached and also below.
Thank you!
_________________
Desired OutputDesired OutputDesired OutputDesired Output
Automation and ScriptingRe: How to parse commas within a List BoxI changed up your script a bit. I continued using your methodology of building a string that contains the elements required to display the Check Boxes.
I also used
Eval( Eval Expr())
To force the evaluation of the string before executing it.

Names Default To Here( 1 );
test = {"a", "b", "c", "d", "e"};
testFin = {};
rows = 2;
remain = Modulo( N Items( test ), rows );
loops = 2 + (remain > 0);
//create a list that groups the original list in groups of 2 (rows)
For( i = 1, i <= loops, i++,
test2 = {};
If( i != loops,
For( j = 1, j <= rows, j++,
test2[j] = test[1];
test = Remove( test, 1 );
)
,
For( j = 1, j <= remain, j++,
test2[j] = test[1];
test = Remove( test, 1 );
)
);
testFin[i] = test2;
);
cb = {};
cancel_check = 0;
ttp = "lineupBox(ncol(" || Char( N Items( testFin ) ) || "),";
For( k = 1, k <= 2, k++,
For( i = 1, i <= N Items( testFin ), i++,
Try( ttp ||= "cb[" || Char( (k - 1) * N Items( testfin ) + i ) || "] = Check Box(\!"" || testFin[i][k] || "\!")," )
)
);
ttp = Substr( ttp, 1, Length( ttp ) - 1 ) || ")";
Eval(
Eval Expr(
testw = New Window( "raaa",
<<MODAL></MODAL>Re: How to parse commas within a List BoxI would avoid Parse() as it can be a nightmare to debug and it will teach you horrible ways of writing JSL script. I would attempt to do something like this or something similar which would avoid using Parse()
Names Default To Here(1);
test = {"a", "b", "c", "d", "e"};
testFin = {};
rows = 2;
remain = Modulo(N Items(test), rows);
loops = 2 + (remain > 0);
//create a list that groups the original list in groups of 2 (rows)
For(i = 1, i <= loops, i++,
test2 = {};
If(i != loops,
For(j = 1, j <= rows, j++,
test2[j] = test[1];
test = Remove(test, 1);
)
,
For(j = 1, j <= remain, j++,
test2[j] = test[1];
test = Remove(test, 1);
)
);
testFin[i] = test2;
);
cancel_check = 0;
cbs = {};
hlb = H List Box();
For(i = 1, i <= N Items(testFin), i++,
hlb << Append(cbs[i] = Check Box(testFin[i]));
);
testw = New Window("raaa",
<<MODAL></MODAL>