cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
GavinS
Level I

Local Function Variables in Button Box

Hello,

I'm looking for a solution to accessing local variables when creating a Button Box inside of a function.  I've seen one post here where the suggested solution was to assign variables to the window namespace.  However, I don't think this will work for the reports I am needing to build since they have multiple reused parts in the same window.

In my example, I just try to print the values of my linked list, but I will want to do a lot more with the final scripts (all functional when testing/cheating using global variables).


// General Component - List Box
make_a_list_box = Function( {list_in},
	{Default Local},
	l_box = List Box( list_in );
	Return( l_box );
);

// General Component - Button linked to a specific list box
linked_button_box = Function( {button_name, target_list_box},
	{Default Local},
	b_box = Button Box( button_name, Print( target_list_box << Get Items ) ); // Name Unresolved: target_list_box
	Return( b_box );
);

// Basic Module - Expect multiple in a shared window
report_module = Function( {list_in, button_name},
	{Default Local},
	report_list = make_a_list_box( list_in );
	report_button = linked_button_box( button_name, report_list );
	report = H List Box( report_list, report_button );
	Print( report_list << Get Items );
	Return( report );
);

// Example Window using multiple modules
New Window( "Test",
	V List Box(
		report_module( {"A", "B", "C"}, "Letter" ),
		report_module( {"1", "2", "3"}, "Number" )
	)
);

 

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: Local Function Variables in Button Box

You can use context box

Names Default To Here(1);

make_a_list_box = Function({list_in},
	{Default Local},
	l_box = List Box(list_in);
	Return(l_box);
);

// General Component - Button linked to a specific list box
linked_button_box = Function({button_name, target_list_box},
	{Default Local},
	b_box = Context Box(
		box:target_list_box = target_list_box, 
		Button Box(button_name, 
			Print(box:target_list_box << Get Items)
		)
	);
	Return(b_box);
);

report_module = Function({list_in, button_name},
	{Default Local},
	report_list = make_a_list_box(list_in);
	report_button = linked_button_box(button_name, report_list);
	report = H List Box(report_list, report_button);
	Print(report_list << Get Items);
	Return(report);
);

nw = New Window("Test", 
	V List Box(
		report_module({"A", "B", "C"}, "Letter"), 
		report_module({"1", "2", "3"}, "Number")
	)
);

Write();
-Jarmo

View solution in original post

1 REPLY 1
jthi
Super User

Re: Local Function Variables in Button Box

You can use context box

Names Default To Here(1);

make_a_list_box = Function({list_in},
	{Default Local},
	l_box = List Box(list_in);
	Return(l_box);
);

// General Component - Button linked to a specific list box
linked_button_box = Function({button_name, target_list_box},
	{Default Local},
	b_box = Context Box(
		box:target_list_box = target_list_box, 
		Button Box(button_name, 
			Print(box:target_list_box << Get Items)
		)
	);
	Return(b_box);
);

report_module = Function({list_in, button_name},
	{Default Local},
	report_list = make_a_list_box(list_in);
	report_button = linked_button_box(button_name, report_list);
	report = H List Box(report_list, report_button);
	Print(report_list << Get Items);
	Return(report);
);

nw = New Window("Test", 
	V List Box(
		report_module({"A", "B", "C"}, "Letter"), 
		report_module({"1", "2", "3"}, "Number")
	)
);

Write();
-Jarmo

Recommended Articles