- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Eval Expression
I am trying to have the user enter several variables, once those variables are deemed ok, then the ok button goes from greyed out to active. I got this working. What I do not have working is the Eval Expr (outputs). This is just a simple thing just to make sure I have this working before I do the calculations. When I run the script, here is a screen shot, the OK button is greyed out:
Then I put plausible values and the ok button shows active after I click the verify inputs:
But it is not running my expression and creating the table. What am I doing wrong? I am on JMP 16.0 Pro. Like I said I did something very simple like create a table just to make sure my script is working before I do a deep dive to what I really need.
Names Default To Here( 0 );
Clear Log();
w = New Window( "Variables",
<<modal,
Border Box( top( 20 ), bottom( 20 ), Left( 20 ), Right( 20 ),
V List Box( // V and H lists nest to organize the display boxes
H Center Box( Text Box( "Enter the Variables for the Calculations" ) ), // a second title, centered
Spacer Box( size( 1, 30 ) ),
H List Box( Text Box( "α: " ), alpha_ent = Number Edit Box() ),
Spacer Box( size( 1, 30 ) ),
H List Box( Text Box( "β: " ), beta_ent = Number Edit Box() ),
Spacer Box( size( 1, 30 ) ),
H List Box( Text Box( "N: " ), N_ent = Number Edit Box() ),
Spacer Box( size( 1, 30 ) ),
H List Box( Text Box( "%: " ), Percent_ent = Number Edit Box() ),
Spacer Box( size( 1, 30 ) ),
H List Box( Text Box( "p0: " ), p0_ent = Number Edit Box() ),
Spacer Box( size( 1, 30 ) ),
H Center Box(
Button Box( "Verify Inputs", // this script runs when the button is pressed...
alpha = alpha_ent << get;
beta = beta_ent << get;
N = N_ent << get;
percent = percent_ent << get;
p0 = p0_ent << get;
i = 1;
DOEN = 0;
For( i = 1, i < 10, i++,
If( 2 ^ i == N,
DOEN = DOEN + 1
)
);
If(
Abs( alpha ) >= 1 | alpha == 0,
alphaw = New Window( "Error!",
<<modal,
Text Box(
"Alpha needs to be between 0 and 1, please fix and try again"
),
),
Abs( beta ) >= 1 | beta == 0,
betaw = New Window( "Error!",
<<modal,
Text Box(
"Beta needs to be between 0 and 1, please fix and try again"
),
),
DOEN == 0,
nw = New Window( "Error!",
<<modal,
Text Box(
"N should be 2\!U1D3A, do not include centerpoints or repeats with N, please fix and try again"
),
),
Abs( percent ) > 90 | percent == 0,
percentw = New Window( "Error!",
<<modal,
Text Box(
"The percent needs to be between 0 and 90%, please fix and try again"
),
),
Abs( p0 ) > 0.90 | p0 == 0,
p0w = New Window( "Error!",
<<modal,
Text Box(
"The p0 needs to be between 0 and 0.90, please fix and try again"
),
)
);
If(
Abs( alpha ) >= 1 | Abs( beta ) >= 1 | DOEN == 0 |
Abs( percent ) > 90 | percent == 0 | Abs( p0 ) > 0.90 | p0 ==
0 | alpha == 0 | beta == 0, bb << Enable( 0 ),
bb << Enable( 1 ),
Eval Expr( output )
);
)
),
bb = Button Box( "OK" ),
bb << Enable( 0 );
)
)
);
Show( alpha );
Show( beta );
Show( DOEN );
Show( percent );
Show( p0 );
output = Expr(
dt = New Table( "Test Table",
New Column( "a", Set Values( {alpha, beta, N, percent, p0} ) )
);
w << closeWindow;
);
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Eval Expression
Move output expression before creation of w and create the output when OK button is pressed.
Names Default To Here(0);
Clear Log();
output = Expr(
dt = New Table("Test Table", New Column("a", Set Values({alpha, beta, N, percent, p0})));
bb << click;
);
w = New Window("Variables",
<<modal,
Border Box(top(20), bottom(20), Left(20), Right(20),
V List Box( // V and H lists nest to organize the display boxes
H Center Box(Text Box("Enter the Variables for the Calculations")), // a second title, centered
Spacer Box(size(1, 30)),
H List Box(Text Box("α: "), alpha_ent = Number Edit Box()),
Spacer Box(size(1, 30)),
H List Box(Text Box("β: "), beta_ent = Number Edit Box()),
Spacer Box(size(1, 30)),
H List Box(Text Box("N: "), N_ent = Number Edit Box()),
Spacer Box(size(1, 30)),
H List Box(Text Box("%: "), Percent_ent = Number Edit Box()),
Spacer Box(size(1, 30)),
H List Box(Text Box("p0: "), p0_ent = Number Edit Box()),
Spacer Box(size(1, 30)),
H Center Box(
Button Box("Verify Inputs", // this script runs when the button is pressed...
alpha = alpha_ent << get;
beta = beta_ent << get;
N = N_ent << get;
percent = percent_ent << get;
p0 = p0_ent << get;
i = 1;
DOEN = 0;
For(i = 1, i < 10, i++,
If(2 ^ i == N,
DOEN = DOEN + 1
)
);
If(
Abs(alpha) >= 1 | alpha == 0,
alphaw = New Window("Error!",
<<modal,
Text Box("Alpha needs to be between 0 and 1, please fix and try again"),
),
Abs(beta) >= 1 | beta == 0,
betaw = New Window("Error!",
<<modal,
Text Box("Beta needs to be between 0 and 1, please fix and try again"),
),
DOEN == 0,
nw = New Window("Error!",
<<modal,
Text Box(
"N should be 2\!U1D3A, do not include centerpoints or repeats with N, please fix and try again"
),
),
Abs(percent) > 90 | percent == 0,
percentw = New Window("Error!",
<<modal,
Text Box("The percent needs to be between 0 and 90%, please fix and try again"),
),
Abs(p0) > 0.90 | p0 == 0,
p0w = New Window("Error!",
<<modal,
Text Box("The p0 needs to be between 0 and 0.90, please fix and try again"),
)
);
If(Abs(alpha) >= 1 | Abs(beta) >= 1 | DOEN == 0 | Abs(percent) > 90 | percent == 0 | Abs(p0) > 0.90 | p0 == 0 | alpha == 0 | beta == 0,
bb << Enable(0),
bb << Enable(1),
write(); //not sure why this is needed here
);
)
),
bb = Button Box("OK", output, << enable(0))
)
)
);
Show(alpha);
Show(beta);
Show(DOEN);
Show(percent);
Show(p0);
And because you are using Modal you could also just create the new table after modal has been closed because the script won't continue execution before modal has been closed.
Here is one example how you could refactor the code a bit if you want to (you can also "force" min/max values to Number Edit Box with << Set Minimum and << Set Maximum). This allows you to also show all error messages in the verifying step if you want to:
Names Default To Here(0);
Clear Log();
validator = function({alpha, beta, N, percent, p0}, {Default Local}, //could also be expression, but this way you avoid creating unnecessary variables
DOEN = 0;
For(i = 1, i < 10, i++,
If(2 ^ i == N,
DOEN = DOEN + 1
)
);
error_list = {};
If(Abs(alpha) >= 1 | alpha == 0,
Insert Into(error_list,"Alpha needs to be between 0 and 1, please fix and try again");
);
If(Abs(beta) >= 1 | beta == 0,
Insert Into(error_list,"Beta needs to be between 0 and 1, please fix and try again");
);
If(DOEN == 0,
Insert Into(error_list,"N should be 2\!U1D3A, do not include centerpoints or repeats with N, please fix and try again");
);
If(Abs(percent) > 90 | percent == 0,
Insert Into(error_list,"The percent needs to be between 0 and 90%, please fix and try again");
);
If(Abs(p0) > 0.90 | p0 == 0,
Insert Into(error_list,"The p0 needs to be between 0 and 0.90, please fix and try again");
);
If(N Items(error_list) > 0,
nw = New Window( "Error!", <<modal, <<Set Window Icon("ErrorSmall"),
Text Box(Concat Items(error_list, "\!N"))
);
0;
,
1;
);
);
w = New Window("Variables",
<<modal,
<< return result,
<< On Validate(
validator(alpha_ent << get, beta_ent << get, N_ent << get, percent_ent << get,p0_ent << get)
),
Border Box(top(20), bottom(20), Left(20), Right(20),
V List Box( // V and H lists nest to organize the display boxes
H Center Box(Text Box("Enter the Variables for the Calculations")), // a second title, centered
Spacer Box(size(1, 30)),
H List Box(Text Box("α: "), alpha_ent = Number Edit Box()),
Spacer Box(size(1, 30)),
H List Box(Text Box("β: "), beta_ent = Number Edit Box()),
Spacer Box(size(1, 30)),
H List Box(Text Box("N: "), N_ent = Number Edit Box()),
Spacer Box(size(1, 30)),
H List Box(Text Box("%: "), Percent_ent = Number Edit Box()),
Spacer Box(size(1, 30)),
H List Box(Text Box("p0: "), p0_ent = Number Edit Box()),
Spacer Box(size(1, 30)),
H List BOx(Button Box("OK"), Button Box("Cancel"));
)
)
);
If(w["Button"] == 1,
dt = New Table("Test Table", New Column("a", Set Values({w["alpha_ent"], w["beta_ent"], w["N_ent"], w["Percent_ent"], w["p0_ent"]})));
, //else
stop();
);
Show(w);
Edit:
Some options for display box usage:
Names Default To Here(0);
Clear Log();
validator = function({alpha, beta, N, percent, p0}, {Default Local},
error_list = {};
DOEN = 0;
For(i = 1, i < 10, i++,
If(2 ^ i == N,
DOEN = DOEN + 1
)
);
If(Abs(alpha) >= 1 | alpha == 0,
Insert Into(error_list,"Alpha needs to be between 0 and 1, please fix and try again");
);
If(Abs(beta) >= 1 | beta == 0,
Insert Into(error_list,"Beta needs to be between 0 and 1, please fix and try again");
);
If(DOEN == 0,
Insert Into(error_list,"N should be 2\!U1D3A, do not include centerpoints or repeats with N, please fix and try again");
);
If(Abs(percent) > 90 | percent == 0,
Insert Into(error_list,"The percent needs to be between 0 and 90%, please fix and try again");
);
If(Abs(p0) > 0.90 | p0 == 0,
Insert Into(error_list,"The p0 needs to be between 0 and 0.90, please fix and try again");
);
If(N Items(error_list) > 0,
nw = New Window( "Error!", <<modal, <<Set Window Icon("ErrorSmall"),
Text Box(Concat Items(error_list, "\!N"))
);
return(0);
);
return(1);
);
w = New Window("Variables",
<<modal,
<< return result,
<< On Validate(
validator(alpha_ent << get, beta_ent << get, N_ent << get, percent_ent << get,p0_ent << get)
),
Border Box(top(20), bottom(20), Left(20), Right(20),
V List Box( align("center"),
Text Box("Enter the Variables for the Calculations"),
Lineup Box(N Col(2), Spacing(5),
Text Box("α: "), alpha_ent = Number Edit Box(),
Text Box("β: "), beta_ent = Number Edit Box(),
Text Box("N: "), N_ent = Number Edit Box(),
Text Box("%: "), Percent_ent = Number Edit Box(),
Text Box("p0: "), p0_ent = Number Edit Box()
),
Spacer Box(Size(0,10)),
Panel Box("Press OK to run",H List Box(Button Box("OK"), Button Box("Cancel"))
),
)
)
);
If(w["Button"] == 1,
dt = New Table("Test Table", New Column("a", Set Values({w["alpha_ent"], w["beta_ent"], w["N_ent"], w["Percent_ent"], w["p0_ent"]})));
, //else
stop();
);
Show(w);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Eval Expression
I think you should be able to just get rid of the eval expr(). If you just do output, it will eval. You could also just do Eval(output). EvalExpr is more for creating dynamic expressions. here's the bit from the scripting index.
EvalExpr returns a copy of the expression with each Expr() clause within x replaced with it's evaluated value
So
Eval Expr( Length( Expr( "X" || Char( 12 ) ) ) ); // returns Length("X12")
If you wanted to evaluate it you'd have to do
Eval(Eval Expr( Length( Expr( "X" || Char( 12 ) ) ) ));
but you're just trying to evaluate an expression I think so you probably don't need evalexpr()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Eval Expression
I tried Eval (output) first and it did not work, so I tried Eval expr() second. I tried output by itself and it did not work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Eval Expression
Move output expression before creation of w and create the output when OK button is pressed.
Names Default To Here(0);
Clear Log();
output = Expr(
dt = New Table("Test Table", New Column("a", Set Values({alpha, beta, N, percent, p0})));
bb << click;
);
w = New Window("Variables",
<<modal,
Border Box(top(20), bottom(20), Left(20), Right(20),
V List Box( // V and H lists nest to organize the display boxes
H Center Box(Text Box("Enter the Variables for the Calculations")), // a second title, centered
Spacer Box(size(1, 30)),
H List Box(Text Box("α: "), alpha_ent = Number Edit Box()),
Spacer Box(size(1, 30)),
H List Box(Text Box("β: "), beta_ent = Number Edit Box()),
Spacer Box(size(1, 30)),
H List Box(Text Box("N: "), N_ent = Number Edit Box()),
Spacer Box(size(1, 30)),
H List Box(Text Box("%: "), Percent_ent = Number Edit Box()),
Spacer Box(size(1, 30)),
H List Box(Text Box("p0: "), p0_ent = Number Edit Box()),
Spacer Box(size(1, 30)),
H Center Box(
Button Box("Verify Inputs", // this script runs when the button is pressed...
alpha = alpha_ent << get;
beta = beta_ent << get;
N = N_ent << get;
percent = percent_ent << get;
p0 = p0_ent << get;
i = 1;
DOEN = 0;
For(i = 1, i < 10, i++,
If(2 ^ i == N,
DOEN = DOEN + 1
)
);
If(
Abs(alpha) >= 1 | alpha == 0,
alphaw = New Window("Error!",
<<modal,
Text Box("Alpha needs to be between 0 and 1, please fix and try again"),
),
Abs(beta) >= 1 | beta == 0,
betaw = New Window("Error!",
<<modal,
Text Box("Beta needs to be between 0 and 1, please fix and try again"),
),
DOEN == 0,
nw = New Window("Error!",
<<modal,
Text Box(
"N should be 2\!U1D3A, do not include centerpoints or repeats with N, please fix and try again"
),
),
Abs(percent) > 90 | percent == 0,
percentw = New Window("Error!",
<<modal,
Text Box("The percent needs to be between 0 and 90%, please fix and try again"),
),
Abs(p0) > 0.90 | p0 == 0,
p0w = New Window("Error!",
<<modal,
Text Box("The p0 needs to be between 0 and 0.90, please fix and try again"),
)
);
If(Abs(alpha) >= 1 | Abs(beta) >= 1 | DOEN == 0 | Abs(percent) > 90 | percent == 0 | Abs(p0) > 0.90 | p0 == 0 | alpha == 0 | beta == 0,
bb << Enable(0),
bb << Enable(1),
write(); //not sure why this is needed here
);
)
),
bb = Button Box("OK", output, << enable(0))
)
)
);
Show(alpha);
Show(beta);
Show(DOEN);
Show(percent);
Show(p0);
And because you are using Modal you could also just create the new table after modal has been closed because the script won't continue execution before modal has been closed.
Here is one example how you could refactor the code a bit if you want to (you can also "force" min/max values to Number Edit Box with << Set Minimum and << Set Maximum). This allows you to also show all error messages in the verifying step if you want to:
Names Default To Here(0);
Clear Log();
validator = function({alpha, beta, N, percent, p0}, {Default Local}, //could also be expression, but this way you avoid creating unnecessary variables
DOEN = 0;
For(i = 1, i < 10, i++,
If(2 ^ i == N,
DOEN = DOEN + 1
)
);
error_list = {};
If(Abs(alpha) >= 1 | alpha == 0,
Insert Into(error_list,"Alpha needs to be between 0 and 1, please fix and try again");
);
If(Abs(beta) >= 1 | beta == 0,
Insert Into(error_list,"Beta needs to be between 0 and 1, please fix and try again");
);
If(DOEN == 0,
Insert Into(error_list,"N should be 2\!U1D3A, do not include centerpoints or repeats with N, please fix and try again");
);
If(Abs(percent) > 90 | percent == 0,
Insert Into(error_list,"The percent needs to be between 0 and 90%, please fix and try again");
);
If(Abs(p0) > 0.90 | p0 == 0,
Insert Into(error_list,"The p0 needs to be between 0 and 0.90, please fix and try again");
);
If(N Items(error_list) > 0,
nw = New Window( "Error!", <<modal, <<Set Window Icon("ErrorSmall"),
Text Box(Concat Items(error_list, "\!N"))
);
0;
,
1;
);
);
w = New Window("Variables",
<<modal,
<< return result,
<< On Validate(
validator(alpha_ent << get, beta_ent << get, N_ent << get, percent_ent << get,p0_ent << get)
),
Border Box(top(20), bottom(20), Left(20), Right(20),
V List Box( // V and H lists nest to organize the display boxes
H Center Box(Text Box("Enter the Variables for the Calculations")), // a second title, centered
Spacer Box(size(1, 30)),
H List Box(Text Box("α: "), alpha_ent = Number Edit Box()),
Spacer Box(size(1, 30)),
H List Box(Text Box("β: "), beta_ent = Number Edit Box()),
Spacer Box(size(1, 30)),
H List Box(Text Box("N: "), N_ent = Number Edit Box()),
Spacer Box(size(1, 30)),
H List Box(Text Box("%: "), Percent_ent = Number Edit Box()),
Spacer Box(size(1, 30)),
H List Box(Text Box("p0: "), p0_ent = Number Edit Box()),
Spacer Box(size(1, 30)),
H List BOx(Button Box("OK"), Button Box("Cancel"));
)
)
);
If(w["Button"] == 1,
dt = New Table("Test Table", New Column("a", Set Values({w["alpha_ent"], w["beta_ent"], w["N_ent"], w["Percent_ent"], w["p0_ent"]})));
, //else
stop();
);
Show(w);
Edit:
Some options for display box usage:
Names Default To Here(0);
Clear Log();
validator = function({alpha, beta, N, percent, p0}, {Default Local},
error_list = {};
DOEN = 0;
For(i = 1, i < 10, i++,
If(2 ^ i == N,
DOEN = DOEN + 1
)
);
If(Abs(alpha) >= 1 | alpha == 0,
Insert Into(error_list,"Alpha needs to be between 0 and 1, please fix and try again");
);
If(Abs(beta) >= 1 | beta == 0,
Insert Into(error_list,"Beta needs to be between 0 and 1, please fix and try again");
);
If(DOEN == 0,
Insert Into(error_list,"N should be 2\!U1D3A, do not include centerpoints or repeats with N, please fix and try again");
);
If(Abs(percent) > 90 | percent == 0,
Insert Into(error_list,"The percent needs to be between 0 and 90%, please fix and try again");
);
If(Abs(p0) > 0.90 | p0 == 0,
Insert Into(error_list,"The p0 needs to be between 0 and 0.90, please fix and try again");
);
If(N Items(error_list) > 0,
nw = New Window( "Error!", <<modal, <<Set Window Icon("ErrorSmall"),
Text Box(Concat Items(error_list, "\!N"))
);
return(0);
);
return(1);
);
w = New Window("Variables",
<<modal,
<< return result,
<< On Validate(
validator(alpha_ent << get, beta_ent << get, N_ent << get, percent_ent << get,p0_ent << get)
),
Border Box(top(20), bottom(20), Left(20), Right(20),
V List Box( align("center"),
Text Box("Enter the Variables for the Calculations"),
Lineup Box(N Col(2), Spacing(5),
Text Box("α: "), alpha_ent = Number Edit Box(),
Text Box("β: "), beta_ent = Number Edit Box(),
Text Box("N: "), N_ent = Number Edit Box(),
Text Box("%: "), Percent_ent = Number Edit Box(),
Text Box("p0: "), p0_ent = Number Edit Box()
),
Spacer Box(Size(0,10)),
Panel Box("Press OK to run",H List Box(Button Box("OK"), Button Box("Cancel"))
),
)
)
);
If(w["Button"] == 1,
dt = New Table("Test Table", New Column("a", Set Values({w["alpha_ent"], w["beta_ent"], w["N_ent"], w["Percent_ent"], w["p0_ent"]})));
, //else
stop();
);
Show(w);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Eval Expression
Thank you! this worked perfectly.