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" )
)
);
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();