如何让按钮框脚本拥有已求值的表达式你好,
我正在尝试创建一个自动添加按钮框的功能,这些按钮框将通过脚本指向各个大纲框(例如,滚动窗口或关闭按钮)。我成功地通过 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 函数之外, 替换为()函数不会对其第一个参数求值。