JMP community expert, I'm from China.
The following problem description comes from machine translation. Please don't mind that the grammar can be a little strange.
I want to create a button column to write some scripts.
I mainly use the following methods to create button columns:
cb = Expr(Col Box("Title"));
for each( {v, i}, list,
Insert Into( cb, button box("name", Script...) )
);I inevitably use variables like "v", "I", etc. in "scripts", but I find that these variables are always present in "scripts" as variables rather than their actual values, which causes my scripts to not work properly.
I tried using Expr (), Eval (), and other functions to convert variables to actual values, but I couldn't get the desired effect.
I simulated a similar scenario using the BigClass.jmp sample data.
Suppose these students are participating in some kind of competition and need to be grouped by age. I want to create a button column that contains the student's name, and then click that button to display their corresponding group.
A sample script is as follows:
Names Default To Here( 1 );
aa_AgeGroup = [10 => "Age Group 1",
11 => "Age Group 1",
12 => "Age Group 1",
13 => "Age Group 1",
14 => "Age Group 2",
15 => "Age Group 2",
16 => "Age Group 2",
17 => "Age Group 2"];
dt = Open( "$sample_data/big class.jmp" );
list_name = dt:name << Get Values;
list_age = dt:age << Get Values;
cb_button = Expr( Col Box( "Name" ) );
fun = Function( {this, ver_age}, //
New Window( "Age Group", //
<<MODAL></MODAL>I hope my friends can teach me how to make variables stored in the button script as actual values, thank you.
Thank you very much for your assistance in resolving my issue so effectively.
I had also considered utilizing Expr(), EvalExpr(), and Eval() to address this matter, but my comprehension of these functions was insufficient for solving the problem.
Your solution not only resolved the issue at hand, but also provided me with a deeper understanding of the integration of these functions.
Once again, thank you Jarmo.
You will have to evaluate the values into your buttons script. Just adding Eval(EvalExpr()) and few Expr() to your script should do the trick (there are also other options)
Names Default To Here(1);
aa_AgeGroup = [10 => "Age Group 1",
11 => "Age Group 1",
12 => "Age Group 1",
13 => "Age Group 1",
14 => "Age Group 2",
15 => "Age Group 2",
16 => "Age Group 2",
17 => "Age Group 2"];
dt = Open("$sample_data/big class.jmp");
list_name = dt:name << Get Values;
list_age = dt:age << Get Values;
cb_button = Expr(Col Box("Name"));
fun = Function({this, ver_age}, //
New Window("Age Group", //
<<MODAL></MODAL>