如何解析列錶框中的逗號你好,
我在 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>