<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How to properly create a button column and use variables in the button's script in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-to-properly-create-a-button-column-and-use-variables-in-the/m-p/763072#M94393</link>
    <description>&lt;P&gt;JMP community expert, I'm from China.&lt;BR /&gt;The following problem description comes from machine translation. Please don't mind that the grammar can be a little strange.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to create a button column to write some scripts.&lt;BR /&gt;I mainly use the following methods to create button columns:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;cb = Expr(Col Box("Title"));
for each( {v, i}, list,
    Insert Into( cb, button box("name", Script...) )
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;I tried using Expr (), Eval (), and other functions to convert variables to actual values, but I couldn't get the desired effect.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I simulated a similar scenario using the BigClass.jmp sample data.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;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.&lt;BR /&gt;A sample script is as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );

aa_AgeGroup = [10 =&amp;gt; "Age Group 1",
11 =&amp;gt; "Age Group 1",
12 =&amp;gt; "Age Group 1",
13 =&amp;gt; "Age Group 1",
14 =&amp;gt; "Age Group 2",
15 =&amp;gt; "Age Group 2",
16 =&amp;gt; "Age Group 2",
17 =&amp;gt; "Age Group 2"];

dt = Open( "$sample_data/big class.jmp" );

list_name = dt:name &amp;lt;&amp;lt; Get Values;

list_age = dt:age &amp;lt;&amp;lt; Get Values;

cb_button = Expr( Col Box( "Name" ) );


fun = Function( {this, ver_age}, 	// 
	New Window( "Age Group", //
		&amp;lt;&amp;lt;modal,
		Text Box( Eval Insert( "^this &amp;lt;&amp;lt; 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, &amp;lt;&amp;lt;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", //
				&amp;lt;&amp;lt;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 ),
		&amp;lt;&amp;lt;Set Scrollable( 15, 0 )
	)
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;CODE class=" language-jsl"&gt;I hope my friends can teach me how to make variables stored in the button script as actual values, thank you. &lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 11 Jun 2024 04:24:02 GMT</pubDate>
    <dc:creator>fengzhuansha</dc:creator>
    <dc:date>2024-06-11T04:24:02Z</dc:date>
    <item>
      <title>How to properly create a button column and use variables in the button's script</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-properly-create-a-button-column-and-use-variables-in-the/m-p/763072#M94393</link>
      <description>&lt;P&gt;JMP community expert, I'm from China.&lt;BR /&gt;The following problem description comes from machine translation. Please don't mind that the grammar can be a little strange.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to create a button column to write some scripts.&lt;BR /&gt;I mainly use the following methods to create button columns:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;cb = Expr(Col Box("Title"));
for each( {v, i}, list,
    Insert Into( cb, button box("name", Script...) )
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;I tried using Expr (), Eval (), and other functions to convert variables to actual values, but I couldn't get the desired effect.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I simulated a similar scenario using the BigClass.jmp sample data.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;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.&lt;BR /&gt;A sample script is as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );

aa_AgeGroup = [10 =&amp;gt; "Age Group 1",
11 =&amp;gt; "Age Group 1",
12 =&amp;gt; "Age Group 1",
13 =&amp;gt; "Age Group 1",
14 =&amp;gt; "Age Group 2",
15 =&amp;gt; "Age Group 2",
16 =&amp;gt; "Age Group 2",
17 =&amp;gt; "Age Group 2"];

dt = Open( "$sample_data/big class.jmp" );

list_name = dt:name &amp;lt;&amp;lt; Get Values;

list_age = dt:age &amp;lt;&amp;lt; Get Values;

cb_button = Expr( Col Box( "Name" ) );


fun = Function( {this, ver_age}, 	// 
	New Window( "Age Group", //
		&amp;lt;&amp;lt;modal,
		Text Box( Eval Insert( "^this &amp;lt;&amp;lt; 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, &amp;lt;&amp;lt;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", //
				&amp;lt;&amp;lt;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 ),
		&amp;lt;&amp;lt;Set Scrollable( 15, 0 )
	)
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;CODE class=" language-jsl"&gt;I hope my friends can teach me how to make variables stored in the button script as actual values, thank you. &lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jun 2024 04:24:02 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-properly-create-a-button-column-and-use-variables-in-the/m-p/763072#M94393</guid>
      <dc:creator>fengzhuansha</dc:creator>
      <dc:date>2024-06-11T04:24:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to properly create a button column and use variables in the button's script</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-properly-create-a-button-column-and-use-variables-in-the/m-p/763073#M94394</link>
      <description>&lt;P&gt;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)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

aa_AgeGroup = [10 =&amp;gt; "Age Group 1",
11 =&amp;gt; "Age Group 1",
12 =&amp;gt; "Age Group 1",
13 =&amp;gt; "Age Group 1",
14 =&amp;gt; "Age Group 2",
15 =&amp;gt; "Age Group 2",
16 =&amp;gt; "Age Group 2",
17 =&amp;gt; "Age Group 2"];

dt = Open("$sample_data/big class.jmp");

list_name = dt:name &amp;lt;&amp;lt; Get Values;

list_age = dt:age &amp;lt;&amp;lt; Get Values;

cb_button = Expr(Col Box("Name"));


fun = Function({this, ver_age}, 	// 
	New Window("Age Group", //
		&amp;lt;&amp;lt;modal,
		Text Box(Eval Insert("^this &amp;lt;&amp;lt; Get Button Name^ was placed in the group \!"^aa_ageGroup[ver_age]^\!""))
	)
);

For Each({{n, a}, i}, across(list_name, list_age), 		//
	Eval(EvalExpr(
		Insert Into(
			cb_button, //
			Button Box(Expr(n), &amp;lt;&amp;lt;Set Function(Function({this}, fun(this, Expr(a)))))
		)		
	));
);


New Window("testWindow", //
	Table Box( 	//
		cb_button,
		Number Col Box("Age_Reference", list_age),
		&amp;lt;&amp;lt;Set Scrollable(15, 0)
	)
);
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 11 Jun 2024 04:36:15 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-properly-create-a-button-column-and-use-variables-in-the/m-p/763073#M94394</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2024-06-11T04:36:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to properly create a button column and use variables in the button's script</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-properly-create-a-button-column-and-use-variables-in-the/m-p/763075#M94396</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Thank you very much for your assistance in resolving my issue so effectively.&lt;BR /&gt;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.&lt;BR /&gt;Your solution not only resolved the issue at hand, but also provided me with a deeper understanding of the integration of these functions.&lt;BR /&gt;Once again, thank you Jarmo.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jun 2024 05:36:35 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-properly-create-a-button-column-and-use-variables-in-the/m-p/763075#M94396</guid>
      <dc:creator>fengzhuansha</dc:creator>
      <dc:date>2024-06-11T05:36:35Z</dc:date>
    </item>
  </channel>
</rss>

