如何讓按鈕框腳本擁有已求值的表達式你好,
我正在嘗試創建一個自動添加按鈕框的功能,這些按鈕框將透過腳本指向各個大綱框(例如,滾動視窗或關閉按鈕)。我成功地透過 For 循環建立了表達式,並將腳本項目的名稱插入到列表中。但是,當我嘗試讓每個按鈕框都有一個唯一的腳本時,它們的腳本名稱卻是表達式「buttonclickexpr」。
如何將表達式中的腳本正確求值並放置為按鈕點擊時要執行的命令?
//an example of how the window could appear
report_win=new window("test", content_VLB=V List Box(), Outline Box("Example: Distribution"), Outline Box("Example: Multivariate"));
//example of the variable that would store the name of scripts that created the OBs
script_new={"Distribution", "Multivariate", "Profiler"};
//the for loop to correctly setup the expression with the correct section name and add a button
For( i = 1, i <= N Items( script_new ), i++,
buttonclickexpr = Expr(
report_win << Scroll Window(
report_win[Outline Box( sectionName)]
)
);
Substitute Into( buttonclickexpr, Expr(sectionName), Char("Example: " ||script_new[i]) );
write(buttonclickexpr);
// Add a button to the list
content_VLB<
<APPEND></APPEND>
<BR />
<LINGO-LABS id="lingo-labs-914974" slang="en-US" mode="CREATE">
<LINGO-LABEL>自動化和腳本編寫</LINGO-LABEL>
</LINGO-LABS>
回覆:如何讓按鈕框腳本具有已求值的表達式你可以使用 Eval(Eval Expr())。
//an example of how the window could appear
report_win = New Window( "test",
content_VLB = V List Box(),
Scroll box (Size(20,1500)),
Outline Box( "Example: Distribution" ),
Scroll box (Size(20,1500)),
Outline Box( "Example: Multivariate" )
);
//example of the variable that would store the name of scripts that created the OBs
script_new = {"Distribution", "Multivariate", "Profiler"};
//the for loop to correctly setup the expression with the correct section name and add a button
For( i = 1, i <= N Items( script_new ), i++,
buttonclickexpr = Expr(
report_win << Scroll Window( report_win[sectionName ] );
Caption(sectionName)
);
Substitute Into( buttonclickexpr, Expr( sectionName ), Char( "Example: " || script_new[i] ) );
Write( buttonclickexpr );
// Add a button to the list
Eval (Eval Expr(content_VLB << append( Button Box( "Go to " || script_new[i], Expr(Name Expr(buttonclickexpr)))) ));
);
在輪廓框(“標籤”)中,tag 是 OutlineBox 的 HelperKey。若要透過標題存取大綱框,可以直接使用標題(無需輪廓框() )。
詳情請參閱“Re: JMP 中的表達式處理:技巧和陷阱”
| 使用 |
|
| 名稱表達式() |
... to retrieve the expression that is stored in the name buttonclickexpr |
| 表達式() |
……標記程式碼——以便評估表達式()可以找到它 |
| 評估表達式() |
... to find 表達式() and evaluate it |
| 評估() |
……在前面的步驟之後,對整個表達式進行求值。 |
回覆:如何讓按鈕框腳本具有已求值的表達式另一種方法: 代替()
[已用於調整按鈕點擊表達式 *)]
兩個步驟合而為一:
For each ({title}, script_new ,
myExpr = Expr(
content_VLB << append( Button Box( "Go to " || title,current report() << Scroll Window( current report()[_sectionName_ ] )));
);
Eval(Substitute (Name Expr(myExpr), Expr( _sectionName_ ), "Example: " || title ));
);
| 使用 |
|
| 代替() |
就像用字串替換一樣——但請記住,參數會被求值!這就是為什麼你必須使用… |
| 名稱表達式() |
……檢索儲存在名稱為myExpr 的表達式 ——未經評估! ! ! |
| 表達式() |
... to protect _sectionName_ from getting evaluated |
| 評估() |
……在前面的步驟之後,對整個表達式進行求值。 |
*)除了 Substitute 函數之外, 替換為()函數不會對其第一個參數求值。