Ed ecco alcuni dei problemi più comuni che potresti incontrare e come risolverli con le espressioni e valutandoli quando necessario.
1. Utilizzo della costante in una formula
Problema:
La tua formula funziona solo una volta e appare così dopo il salvataggio e la riapertura:

Soluzione:
Inserisci un'espressione in un'altra utilizzando Eval Insert, Eval Expr, Parse e Substitute . La maggior parte delle volte utilizzo 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. Utilizzo di costanti nello script grafico
Problema:
Ti ritroverai con uno script come questo
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);
)}
)
)
);
Soluzione:
Usa Eval(EvalExpr()) (o Substitute() è un'altra buona opzione)
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. Impostazione delle variabili come limiti delle specifiche
Problema:
I limiti delle specifiche non vengono impostati correttamente
Soluzione:
Inizia lasciando che JMP crei il codice (aggiungi la proprietà della colonna e prendi il codice dal registro avanzato o fai clic con il pulsante destro del mouse sulla colonna e "Copia proprietà colonna". Ottieni qualcosa del genere
Data Table("Big Class"):height << Set Property(
"Spec Limits",
{LSL(11), USL(22), Target(12), Show Limits(1)}
);
Migliora questo script per utilizzare le variabili
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. Aggiunta di script di tabella alla tabella
Problema:
Alla fine ti ritroverai con uno script di tabella che dice qualcosa del genere

Soluzione:
Eval(EvalExpr()) con nome Expr(). Questo non creerà affatto il grafico. Se vuoi eseguirlo usa << Esegui Script("Il mio bel grafico") o valuta l'espressione
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>ma in casi come questo la maggior parte delle volte utilizzerei << Salva script nella tabella dati, ma questo eseguirà la piattaforma quindi ricordati di chiuderla</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. Crea formule basate sulle selezioni dell'utente dalle caselle di riepilogo Col
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. Usa le espressioni per creare interfacce utente (non l'esempio migliore)
Problema:
Il codice diventa goffo
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")
)
);
Problema2:
Il mio codice non funziona (potrebbe accadere perché la finestra non sempre conosce tutte le variabili)
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
)
);

Soluzione 1:
Valutare l'espressione
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))
)
);
))
Soluzione2:
In questo caso potresti anche usare << 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);
)))
);
Soluzione 3:
Combina
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));
)))
);
));
Soluzione 4:
Usa la funzione (la soluzione 3 potrebbe essere più robusta)
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);
)))
);
Soluzione5:
Usa la funzione per costruire i pulsanti
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")
);