cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
Mewbornn
Level I

Function to reference

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.  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:

 

OutputTable = Current Data Table();

HList = H List Box( OutputTable << Get as Report() );
	//Show(Column(OutputTable, 3)[1]);


SavingVlb = V List Box( Text Box( "Save to External Table" ) );
For( i = 1, i < N Rows( OutputTable ) + 1, i++, 

	BB = Button Box( "Save",
		<<setFunction(
			Function( {i}, 
				
				Print( Column( OutputTable, 3 )[i] );
		
			)
		)
	);

	Insert Into( SavingVlb, BB );

);
Insert Into( HList, SavingVlb );
New Window( "test", HList );

Mewbornn_0-1686778020773.png

 

 

Any help would be greatly appreciated. 

1 ACCEPTED SOLUTION

Accepted Solutions
ErraticAttack
Level VI

Re: Function to reference

Note that when the attached script / function to the ButtonBox runs, it has no view of the scope for which it was created.  This differs from other programming languages (like Python) which maintain scope for when functions were created.

 

In JSL, use the Eval( Eval Expr( ... Expr( var ) ... ) ) construct to pre-evaluate certain parts of the code.  Here is an example.

 

Also, I'd use the ColBox() function to add the buttons as it will auto-align all cells:

OutputTable = Current Data Table();

HList = H List Box( OutputTable << 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 )] << Append( col box );

For( i = 1, i < N Rows( OutputTable ) + 1, i++, 
	
	Eval( Eval Expr(
	BB = Button Box( "Save",
		<<setFunction(
			Print( Column( OutputTable, 3 )[Expr( i )] );
		)
	);
	) );
	col box << Add Element( bb )

);
Insert Into( HList, SavingVlb );
New Window( "test", HList );
Jordan

View solution in original post

1 REPLY 1
ErraticAttack
Level VI

Re: Function to reference

Note that when the attached script / function to the ButtonBox runs, it has no view of the scope for which it was created.  This differs from other programming languages (like Python) which maintain scope for when functions were created.

 

In JSL, use the Eval( Eval Expr( ... Expr( var ) ... ) ) construct to pre-evaluate certain parts of the code.  Here is an example.

 

Also, I'd use the ColBox() function to add the buttons as it will auto-align all cells:

OutputTable = Current Data Table();

HList = H List Box( OutputTable << 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 )] << Append( col box );

For( i = 1, i < N Rows( OutputTable ) + 1, i++, 
	
	Eval( Eval Expr(
	BB = Button Box( "Save",
		<<setFunction(
			Print( Column( OutputTable, 3 )[Expr( i )] );
		)
	);
	) );
	col box << Add Element( bb )

);
Insert Into( HList, SavingVlb );
New Window( "test", HList );
Jordan