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,
Text Box( Eval Insert( "^this << Get Button Name^ was placed in the group \!"^aa_ageGroup[ver_age]^\!"" ) )
)
);
For Each( {{n, a}, i}, across( list_name, list_age ), //
Insert Into(
cb_button, //
Button Box( n, <<Set Function( Function( {this}, fun( this, a ) ) ) )
)
);
// Perhaps when the above two pieces of code are combined, the cause of the exception will be more intuitive
/*
For Each( {{n, a}, i}, across( list_name, list_age ), //
Insert Into(
cb_button, //
Button Box( n,
New Window( "Age Group", //
<<modal,
Text Box( n || " was placed in the group \!"" || aa_ageGroup[a] || "\!"" )
)
)
)
);
*/
New Window( "testWindow", //
Table Box( //
cb_button,
Number Col Box( "Age_Reference", list_age ),
<<Set Scrollable( 15, 0 )
)
);
I hope my friends can teach me how to make variables stored in the button script as actual values, thank you.