如何解析列表框中的逗号你好,
我使用的是 JMP 18.1.2 版本,正在尝试创建一个复选框矩阵。最后一步我搞不懂,如何根据行数动态创建 H 列表框。
这是我当前的代码:
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>
<P>我尝试运行它时遇到的错误是:</P>
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]);
所需的输出(如果我只是用 ttp 替换解析并运行它)已附加并在下面。
谢谢你!
_________________
Desired OutputDesired OutputDesired Output期望输出
<LINGO-LABS id="lingo-labs-870668" slang="en-US" mode="UPDATE"><LINGO-LABEL>自动化和脚本</LINGO-LABEL></LINGO-LABS>回复:如何解析列表框中的逗号我稍微修改了你的脚本。我继续沿用你的方法,构建一个包含显示复选框所需元素的字符串。
我也用过
Eval(Eval Expr())
在执行字符串之前强制对其进行评估。

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>回复:如何解析列表框中的逗号我会避免使用 Parse(),因为它的调试过程可能非常糟糕,而且会教你一些糟糕的 JSL 脚本编写方法。我会尝试这样做或类似的方法,避免使用 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>