以下是您可能遇到的一些非常常見的問題,以及如何使用表達式並在需要時評估它們來解決它們。
1. 在公式中使用常數
問題:
您的公式僅有效一次,儲存並重新開啟後如下所示:

解決方案:
使用 Eval Insert、Eval Expr、Parse 和 Substitute 將一個表達式插入另一個表達式。 大多數時候我使用 Eval(EvalExpr())。
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
value_to_add = 5;
Eval(EvalExpr(
dt << New Column("HeightAddFive", Numeric, Continuous, Formula(
Expr(value_to_add) + :height
));
));
2. 在圖形腳本中使用常數
問題:
你最終會得到這樣的腳本
Graph Builder(
Show Control Panel(0),
Variables(X(:height), Y(:weight), Overlay(:sex)),
Elements(Points(X, Y, Legend(1)), Smoother(X, Y, Legend(2))),
SendToReport(
Dispatch(
{},
"Graph Builder",
FrameBox,
{Add Graphics Script(
7,
Description(""),
Pen Color(color_to_use);
Pen Size(size_to_use);
H Line(value_to_add);
)}
)
)
);
解決方案:
使用 Eval(EvalExpr()) (或 Substitute() 是另一個不錯的選擇)
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
value_to_add = 80;
gb = dt << Run Script("Graph Builder Smoother Line");
color_to_use = "Red";
size_to_use = 2;
Eval(EvalExpr(
Report(gb)[FrameBox(1)] << Add Graphics Script(
Pen Color(Expr(color_to_use));
Pen Size(Expr(size_to_use));
H Line(Expr(value_to_add));
);
));
3. 將變數設定為規格限制
問題:
規格限制設定不正確
解決方案:
首先讓 JMP 建立程式碼(新增列屬性並從增強日誌中取得程式碼或右鍵單擊列並「複製列屬性」)。 你會得到這樣的東西
Data Table("Big Class"):height << Set Property(
"Spec Limits",
{LSL(11), USL(22), Target(12), Show Limits(1)}
);
改進此腳本以使用變數
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
aa_specs = Associative Array();
aa_specs["height"] = ["LSL" => 50, "USL" => 80];
aa_specs["weight"] = ["LSL" => 60, "USL" => 160];
For Each({col_name}, dt << Get Column Names("String"),
If(Contains(aa_specs, col_name),
Eval(EvalExpr(
Column(dt, col_name) << Set Property("Spec Limits" ,{
LSL(Expr(aa_specs[col_name]["LSL"])),
USL(Expr(aa_specs[col_name]["USL"])),
Target(Expr((aa_specs[col_name]["LSL"] + aa_specs[col_name]["USL"])/2)),
Show Limits(1)
})
));
);
);
4.向表格中新增表格腳本
問題:
你最終得到的表腳本是這樣的

解決方案:
Eval(EvalExpr()) 與名稱 Expr()。 這根本不會創建圖表。 如果你想要執行它,請使用 << Run Script("My Nice graph") 或評估表達式
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
gb_expr = Expr(dt << Graph Builder(
Show Control Panel(0),
Variables(X(:height), Y(:weight), Overlay(:sex)),
Elements(Points(X, Y, Legend(1)), Smoother(X, Y, Legend(2))),
));
Eval(EvalExpr(
dt << New Script("My nice graph", Expr(Name Expr(gb_expr)));
));
// dt << Run Script("My nice graph");
// Eval(gb_expr);
</CODE>但在這種情況下,我大多數時候會使用 << 將腳本儲存到資料表,但這將運行平台,因此請記住關閉它</P>
<P> </P>
<PRE><CODE class=" language-jsl">Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
gb_expr = Expr(dt << Graph Builder(
Show Control Panel(0),
Variables(X(:height), Y(:weight), Overlay(:sex)),
Elements(Points(X, Y, Legend(1)), Smoother(X, Y, Legend(2))),
));
gb = Eval(gb_expr);
gb << Save Script to Data Table("My nice graph");
gb << Close Window;
Wait(0);
5. 根據使用者從列列錶框中的選擇建立公式
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
nw = New Window("Selections",
clb_x = Col List Box(dt, << Set items({"height"})),
clb_y = Col List Box(dt, << Set items({"weight"}))
);
x_selection = clb_x << get items;
y_selection = clb_y << get items; // these are strings
wait(2);
nw << Close Window;
// Using Eval(EvalExpr())
Eval(EvalExpr(
dt << New Column("Multiplication_EvalExpr", Numeric, Continuous, Formula(
Expr(NameExpr(AsColumn(dt, x_selection))) * Expr(NameExpr(AsColumn(dt, y_selection)))
));
));
// Using Eval(Substitute())
Eval(Substitute(
Expr(dt << New Column("Multiplication_EvalSubstitute", Numeric, Continuous, Formula(_xcol_ * _ycol_))),
Expr(_xcol_), Name Expr(AsColumn(dt, x_selection)),
Expr(_ycol_), Name Expr(AsColumn(dt, y_selection))
));
6. 使用表達式建立使用者介面(不是最好的例子)
問題:
程式碼變得笨拙
Names Default To Here(1);
nw = New Window("asdas",
Button Box("Perform Action1",
Caption("Perform Action1")
),
Button Box("Perform Action2",
Caption("Perform Action2")
),
Button Box("Perform Action3",
Caption("Perform Action3")
)
);
問題2:
我的程式碼不起作用(可能會發生,因為視窗並不總是知道所有變數)
Names Default To Here(1);
caption_expr = Expr(
Caption("Perform Action");
);
nw = New Window("asdas",
Button Box("Perform Action1",
caption_expr
),
Button Box("Perform Action2",
caption_expr
),
Button Box("Perform Action3",
caption_expr
)
);

解決方案1:
評估表達式
Names Default To Here(1);
caption_expr = Expr(
Caption("Perform Action");
);
Eval(EvalExpr(
nw = New Window("asdas",
Button Box("Perform Action1",
Expr(Name Expr(caption_expr))
),
Button Box("Perform Action2",
Expr(Name Expr(caption_expr))
),
Button Box("Perform Action3",
Expr(Name Expr(caption_expr))
)
);
))
解決方案2:
在這種情況下,您也可以使用 << Set Function(Function([}))
Names Default To Here(1);
nw = New Window("asdas",
Button Box("Perform Action1", << Set Function(function({this},
Caption(this << get button name);
))),
Button Box("Perform Action2", << Set Function(function({this},
Caption(this << get button name);
))),
Button Box("Perform Action3", << Set Function(function({this},
Caption(this << get button name);
)))
);
解決方案3:
結合
Names Default To Here(1);
button_caption_expr = Expr(
Caption(this << get button name);
);
Eval(EvalExpr(
nw = New Window("asdas",
Button Box("Perform Action1", << Set Function(function({this},
Expr(NameExpr(button_caption_expr));
))),
Button Box("Perform Action2", << Set Function(function({this},
Expr(NameExpr(button_caption_expr));
))),
Button Box("Perform Action3", << Set Function(function({this},
Expr(NameExpr(button_caption_expr));
)))
);
));
解決方案4:
使用函數(解決方案3可能更穩健)
Names Default To Here(1);
show_btn_caption = function({btn_ref}, {Default Local},
Caption(btn_ref << get button name);
);
nw = New Window("asdas",
Button Box("Perform Action1", << Set Function(function({this},
show_btn_caption(this);
))),
Button Box("Perform Action2", << Set Function(function({this},
show_btn_caption(this);
))),
Button Box("Perform Action3", << Set Function(function({this},
show_btn_caption(this);
)))
);
解決方案5:
使用函數來建立按鈕
Names Default To Here(1);
create_btn = function({btn_title}, {Default Local},
btn = Button Box(btn_title, << Set Function(function({this},
Caption(btn_ref << get button name);
)));
return(btn);
);
nw = New Window("asdas",
create_btn("Perform Action1"),
create_btn("Perform Action2"),
create_btn("Perform Action3")
);