cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Submit your abstract to the call for content for Discovery Summit Americas by April 23. Selected abstracts will be presented at Discovery Summit, Oct. 21- 24.
Discovery is online this week, April 16 and 18. Join us for these exciting interactive sessions.
Choose Language Hide Translation Bar
MuttonChops
Level III

For Loop inside a tab box where each loop creates a different tab in the window

I'm attempting to loop through a variable list of tools (ChamberTool or Cham) to create a list.  Then using that list I create a contour of the data by date where each chamber is a separate tab on a tab box window.  I've done each of these things independently but my particular issue is creating a tab for each tool from this variable list.  Maybe my approach is way off but here is my script.  

 

First, here are the two bits of script I have that work.  I hand wave over the scripting of the parts that I already know how to do and to keep this post more brief and not detract from my main problem statement.

ContourG = dt << Contour stuff here;

Graph = new window("Contours", tab box(
		"Tab Name Here", (vlistbox(ContourG)),
));

But when i try to run a for loop i am completely broken.

Cham = Associative Array(Column(dt_stacked, "Chamber") << Get Values) << Get Keys;Associative Array(Column(dt_stacked, "Chamber")<< Get Values)<<Get Keys;

Graph = new window("Contours", tab box(
	For (x=1, x<=nitems(Cham), x++,
		ChamberTool= Cham[x];
		G_Contour = Cham[x];
		ContourG = dt_stacked << Contour Plot(
			X( :XLoc, :YLoc ),	Y( :Thickness ),
			Where( :Chamber == ChamberTool ),	By(:Date),
			Chart Parameter stuff here,	SendToReport( other stuff here)	),
		ChamberTool, (vlistbox(ContourG)),
)));
11 REPLIES 11
txnelson
Super User

Re: For Loop inside a tab box where each loop creates a different tab in the window

The syntax you are using to create the new tabs is not correct;  Below is the example taken directly from the Scripting Index, on how to add a new tab.  Infact, the example shows 2 ways to do that.  Your code only generates one tab.

Names Default To Here( 1 );
New Window( "Example",
	tb = Tab Box(
		Tab Page Box(
			"First Tab",
			Tip( "First Tab Tooltip" ),
			Button Box( "Press One" )
		),
		Tab Page Box(
			"Second Tab",
			Closeable( 1 ),
			Button Box( "Press Two" )
		),
		Tab Page Box(
			"Third Tab",
			Icon( "Nominal" ),
			Button Box( "Press Three" )
		)
	)
);
Wait( 1 );
tb << Add(
	"Fourth Tab",
	Button Box( "Press Four" )
);
Jim
MuttonChops
Level III

Re: For Loop inside a tab box where each loop creates a different tab in the window

@txnelson, my code was my attempt to create a loop, based on a variable list, to have each discrete item in the list be its own tab.  The example you gave looks like a way to hard code a specific number of tabs but in my case the number of tabs would change.  For example, if my dataset one day has 5 distinct entities in my list then my code should generate 5 tabs, one for each entity.  But the next day my dataset might be 8 entities.  

 

And an unrelated question, any ide how i can update my email address on my account?  I realized that my account is tied to an address that I no longer have access to and I can't for the life of me figure out how to update it.

txnelson
Super User

Re: For Loop inside a tab box where each loop creates a different tab in the window

My previous post was not completly hard wired.  It showed both a hard coded method, and a method that would allow you to decide to add tabs whenever you needed to.  But to make it more direct, here is a reworked script that uses a JSL list to determine the tabs that need to be added

Names Default To Here( 1 );

tabList = {"First", "Second", "Third", "Fourth"};
New Window( "Example", tb = Tab Box() );

For( i = 1, i <= N Items( tabList ), i++,
	tb << Add(
		tabList[i] || " Tab",
		Button Box( "Press " || tabList[i] )
	)
);
Jim
jietan25
Level II

Re: For Loop inside a tab box where each loop creates a different tab in the window

Is that possible dynamically create a 2nd layer of Tab Boxes, my data has multi-layers of data, thank you.  

 

Names Default To Here( 1 );

tabList = {"First", "Second", "Third", "Fourth"};
New Window( "Example", tb = Tab Box() ); For( i = 1, i <= N Items( tabList ), i++, tb << Add( tabList[i] || " Tab",
//another layer of tabs goes here
Button Box( "Press " || tabList[i] ) ) );

 

ian_jmp
Staff

Re: For Loop inside a tab box where each loop creates a different tab in the window

Building on Jim's example:

NamesDefaultToHere(1);

// Make two lists that will define the two-level hierarchical tab structure
nFirst = 4;
nSecondMax = 5;
tabListFirst = {};			// A List
tabListSecond = {};			// A list of lists
for(i=1, i<=nFirst, i++,
	InsertInto(tabListFirst, "Tab "|| Char(i));
	secondList = {};
	for(ii=1, ii<=randomInteger(1, nSecondMax), ii++,
		InsertInto(secondList, "Tab "|| Char(ii))
		);
	InsertInto(tabListSecond, evalList(List(secondList)));
	);


// Use these lists to build the UI
tb = Tab Box();
For( i = 1, i <= N Items( tabListFirst ), i++,
	tb2 = TabBox();
	for(ii = 1, ii <= NItems(tabListSecond[i]), ii++,
		tb2 << add(
				tabListSecond[i][ii] || " Tab",
				Button Box( "Press " || tabListSecond[i][ii] )
				);
		);
	tb << Add(tabListFirst[i] || " Tab", tb2);
	);
New Window( "Example", tb );
jietan25
Level II

Re: For Loop inside a tab box where each loop creates a different tab in the window

Thank you, that is exactly what i am looking for, my data has 4 level, and number of tab on the next level is based on tab value from previous level..
jietan25
Level II

Re: For Loop inside a tab box where each loop creates a different tab in the window

4 level tab box example:

 

Names Default To Here( 1 );

// Make multiple lists that will define the multi-level hierarchical tab structure
nFirst = 5;
nSecondMax = 5;
nThirdMax = 5;
nForthMax = 5;

tabListFirst = {};			// first lists
tabListSecond = {};			// second lists
tabListThird = {}; 			// third lists
tabListForth = {}; 			// forth lists

For( i = 1, i <= nFirst, i++, //first level
	Insert Into( tabListFirst, " L1 Tab " || Char( i ) );
	secondList = {};
	For( ii = 1, ii <= nSecondMax, ii++, //second level
		Insert Into( secondList, "L2 Tab " || Char( ii ) );
		thirdList = {};
		For( iii = 1, iii <= nThirdMax, iii++,//third level
			Insert Into( thirdList, "L3 Tab " || Char( iii ) );			
			forthList = {};
			For( iiii = 1, iiii <= nForthMax, iiii++,//forth level
				Insert Into( forthList, "L4 Tab " || Char( iiii ) )
				);
			Insert Into( tabListForth, Eval List( List( forthList ) ) );				
		);
		Insert Into( tabListThird, Eval List( List( ThirdList ) ) );
	);
	Insert Into( tabListSecond, Eval List( List( secondList ) ) );
);
/*
Show( tabListFirst );
Show( tabListSecond );
Show( tabListThird );
Show( tabListForth );
*/

// Use these lists to build the UI
tb = Tab Box(); //first level of Tab Box
For( i = 1, i <= N Items( tabListFirst ), i++,
	tb2 = Tab Box(); //second level of Tab Box
	For( ii = 1, ii <= N Items( tabListSecond[i] ), ii++,
		tb3 = Tab Box();  //third level of Tab Box
		For (iii = 1, iii <= NItems ( tabListThird[ii]), iii++,
			tb4 = Tab Box();
			For (iiii = 1, iiii <= NItems ( tabListForth[iii]), iiii++,
				tb4 << Add( tabListForth[iii][iiii] || " Tab", 
				Text Box( tabListFirst[i] ||"->"|| tabListSecond[ii][iii] ||"->"|| tabListThird[ii][iii] ||"->"|| tabListForth[iii][iiii]) )
				);
				tb3 << Add(tabListThird[ii][iii] || " Tab", tb4);
			);
			tb2 << Add ( tabListSecond[i][ii] || " Tab", tb3);
		);
		tb << Add( tabListFirst[i] || " Tab", tb2 );
	);
New Window( "Example", tb );
	
jietan25
Level II

Re: For Loop inside a tab box where each loop creates a different tab in the window

 

 

Text Box( tabListFirst[i] ||"->"|| tabListSecond[ii][iii] ||"->"|| tabListThird[ii][iii] ||"->"|| tabListForth[iii][iiii]) )

-->

Text Box( tabListFirst[i] ||"->"|| tabListSecond[i][ii] ||"->"|| tabListThird[ii][iii] ||"->"|| tabListForth[iii][iiii]) )

minor update...... 

ian_jmp
Staff

Re: For Loop inside a tab box where each loop creates a different tab in the window

Of course there are lots of ways to design a UI. But with a four level hierarchy, I would consider using a local data filter with the 'conditional' option:

// Conditional (hierarchical) local data filter

Names Default To Here( 1 );

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

gb = dt << Graph Builder(
					Size( 529, 563 ),
					Show Control Panel( 0 ),
					Show Legend( 0 ),
					Variables( X( :weight ), Y( :height ) ),
					Elements( Points( X, Y, Legend( 5 ) ) ),
					Local Data Filter(
						Conditional,
						Add Filter(
							columns( :sex, :age, :name ),
							Display( :sex, Size( 149, 28 ), List Display ),
							Display( :age, Size( 149, 84 ), List Display ),
							Display( :name, Size( 149, 210 ), List Display )
						)
					)
				);