<?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 Re: Function to reference in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Function-to-reference/m-p/642572#M83937</link>
    <description>&lt;P&gt;Note that when the attached script / function to the ButtonBox runs, it has no view of the scope for which it was created.&amp;nbsp; This differs from other programming languages (like Python) which maintain scope for when functions were created.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In JSL, use the &lt;CODE class=" language-jsl"&gt;Eval( Eval Expr( ... Expr( var ) ... ) )&lt;/CODE&gt; construct to pre-evaluate certain parts of the code.&amp;nbsp; Here is an example.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, I'd use the ColBox() function to add the buttons as it will auto-align all cells:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;OutputTable = Current Data Table();

HList = H List Box( OutputTable &amp;lt;&amp;lt; Get as Report() );
	//Show(Column(OutputTable, 3)[1]);

SavingVlb = V List Box( Text Box( "Save to External Table" ) );

col box = Col Box( "" );
hlist[Table Box( 1 )] &amp;lt;&amp;lt; Append( col box );

For( i = 1, i &amp;lt; N Rows( OutputTable ) + 1, i++, 
	
	Eval( Eval Expr(
	BB = Button Box( "Save",
		&amp;lt;&amp;lt;setFunction(
			Print( Column( OutputTable, 3 )[Expr( i )] );
		)
	);
	) );
	col box &amp;lt;&amp;lt; Add Element( bb )

);
Insert Into( HList, SavingVlb );
New Window( "test", HList );&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 14 Jun 2023 23:42:42 GMT</pubDate>
    <dc:creator>ErraticAttack</dc:creator>
    <dc:date>2023-06-14T23:42:42Z</dc:date>
    <item>
      <title>Function to reference</title>
      <link>https://community.jmp.com/t5/Discussions/Function-to-reference/m-p/642544#M83935</link>
      <description>&lt;P&gt;I am inserting two Boxes into an H List Box. The First is a report from a table. That table can have a varying number of rows depending on what happens previously in script, but always has the same number of columns. The second box I am inserting, is a V List Box. For Each row of the table, I want a button box added to the V List, and for it to be able to reference the respective rows data. ie. Button Box 1 references the value in Row 1, Column 3, in the table in the H List Box. My problem is I cant seem to reference that value, when I am using a "for loop" to create the number of Button boxes equal to the number of rows in the table.&amp;nbsp; I know it is trying to reference the cell with the row = i at the end of the for loop, I just dont know how to get it to "save the value of i" for each button box. My Current Code is shown below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;OutputTable = Current Data Table();

HList = H List Box( OutputTable &amp;lt;&amp;lt; Get as Report() );
	//Show(Column(OutputTable, 3)[1]);


SavingVlb = V List Box( Text Box( "Save to External Table" ) );
For( i = 1, i &amp;lt; N Rows( OutputTable ) + 1, i++, 

	BB = Button Box( "Save",
		&amp;lt;&amp;lt;setFunction(
			Function( {i}, 
				
				Print( Column( OutputTable, 3 )[i] );
		
			)
		)
	);

	Insert Into( SavingVlb, BB );

);
Insert Into( HList, SavingVlb );
New Window( "test", HList );&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Mewbornn_0-1686778020773.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/53852i044FA11E02726D1F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Mewbornn_0-1686778020773.png" alt="Mewbornn_0-1686778020773.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be greatly appreciated.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jun 2023 21:32:34 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Function-to-reference/m-p/642544#M83935</guid>
      <dc:creator>Mewbornn</dc:creator>
      <dc:date>2023-06-14T21:32:34Z</dc:date>
    </item>
    <item>
      <title>Re: Function to reference</title>
      <link>https://community.jmp.com/t5/Discussions/Function-to-reference/m-p/642572#M83937</link>
      <description>&lt;P&gt;Note that when the attached script / function to the ButtonBox runs, it has no view of the scope for which it was created.&amp;nbsp; This differs from other programming languages (like Python) which maintain scope for when functions were created.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In JSL, use the &lt;CODE class=" language-jsl"&gt;Eval( Eval Expr( ... Expr( var ) ... ) )&lt;/CODE&gt; construct to pre-evaluate certain parts of the code.&amp;nbsp; Here is an example.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, I'd use the ColBox() function to add the buttons as it will auto-align all cells:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;OutputTable = Current Data Table();

HList = H List Box( OutputTable &amp;lt;&amp;lt; Get as Report() );
	//Show(Column(OutputTable, 3)[1]);

SavingVlb = V List Box( Text Box( "Save to External Table" ) );

col box = Col Box( "" );
hlist[Table Box( 1 )] &amp;lt;&amp;lt; Append( col box );

For( i = 1, i &amp;lt; N Rows( OutputTable ) + 1, i++, 
	
	Eval( Eval Expr(
	BB = Button Box( "Save",
		&amp;lt;&amp;lt;setFunction(
			Print( Column( OutputTable, 3 )[Expr( i )] );
		)
	);
	) );
	col box &amp;lt;&amp;lt; Add Element( bb )

);
Insert Into( HList, SavingVlb );
New Window( "test", HList );&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 14 Jun 2023 23:42:42 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Function-to-reference/m-p/642572#M83937</guid>
      <dc:creator>ErraticAttack</dc:creator>
      <dc:date>2023-06-14T23:42:42Z</dc:date>
    </item>
  </channel>
</rss>

