cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Have your say in shaping JMP's future by participating in the new JMP Wish List Prioritization Survey
Choose Language Hide Translation Bar
JanneI
Level III

Nested loops with List boxes

I am trying to construct a 2D-matrix with 2 nested FOR-loops used in the mouse over hover labels (Graph builder -> Hover Label Editor -> Graphlet).

I provide here a simplified example for 2*2 matrix. 

 

hlb  = H List Box();
vlb  = V List Box();

For (row=1, row<=2, row++,
	For (col=1, col<=2, col++,
		hlb << append(Text Box("Row: "|| char(row) ||", Col: "|| char(col) ))
		);
	vlb << append(hlb);
);
vlb << get picture;

Script above results to wrong output:

 

JanneI_0-1645115699038.png

 

To get correct outcome, I need somehow reset the H List Box. However, if I add hlb << Set Items({}); like below, the outcome is very same as above (ie. not correct).

hlb  = H List Box();
vlb  = V List Box();

For (row=1, row<=2, row++,
	For (col=1, col<=2, col++,
		hlb << append(Text Box("Row: "|| char(row) ||", Col: "|| char(col) ))
		);
	vlb << append(hlb);
	hlb << Set Items({});
);
vlb << get picture;

I also tried to delete and recreate the H List Box as below. This does not work either as it deletes the H List Box object already fed in to V List Box

hlb  = H List Box();
vlb  = V List Box();

For (row=1, row<=2, row++,
	For (col=1, col<=2, col++,
		hlb << append(Text Box("Row: "|| char(row) ||", Col: "|| char(col) ))
		);
	vlb << append(hlb);
	hlb << Delete;
	hlb  = H List Box();
);
vlb << get picture;

Any further advices? My JMP version is 16.2

 

Thanks;

Janne

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Nested loops with List boxes

I believe this is what you want

txnelson_0-1645117298204.png

vlb = V List Box();

For( row = 1, row <= 2, row++,
	hlb = H List Box();
	For( col = 1, col <= 2, col++,
		hlb << append( Text Box( "Row: " || Char( row ) || ", Col: " || Char( col ) ) )
	);
	vlb << append( hlb );
);
New Window( "show", vlb << get picture );

 

Jim

View solution in original post

4 REPLIES 4
txnelson
Super User

Re: Nested loops with List boxes

I believe this is what you want

txnelson_0-1645117298204.png

vlb = V List Box();

For( row = 1, row <= 2, row++,
	hlb = H List Box();
	For( col = 1, col <= 2, col++,
		hlb << append( Text Box( "Row: " || Char( row ) || ", Col: " || Char( col ) ) )
	);
	vlb << append( hlb );
);
New Window( "show", vlb << get picture );

 

Jim
jthi
Super User

Re: Nested loops with List boxes

You could also use Table Box or Lineup Box with N Col:

Names Default To Here(1);

vlb = V List Box();

For(row = 1, row <= 2, row++,
	hlb = H List Box();
	For(col = 1, col <= 2, col++,
		hlb << append(Text Box("Row: " || Char(row) || ", Col: " || Char(col) || " || "))
	);
	vlb << append(hlb);
);

lb = Lineup Box(N Col(2));

cols = 2;
rows = 2;
For(i = 1, i <= cols * rows, i++,
	row = Ceiling(i / 2);
	col = !Modulo(i, 2) + 1; //just some calculation which works in this case
	Show(col);
	lb << append(Text Box("Row: " || Char(row) || ", Col: " || Char(col) || " || "));
);

//one option
tb = Table Box("",
	String Col Box("row1", {"Row: 1", "Row: 2"}),
	String Col Box("col1", {"Col: 1", "Col: 1"}),
	String Col Box("row1", {"Row: 1", "Row: 2"}),
	String Col Box("col1", {"Col: 2", "Col: 2"}),
);

New Window("",
	Lineup Box(N Col(1), 
		Text Box("V List Box"), 
		vlb,
		Text Box("Lineup"), 
		lb,
		Text Box("Table Box"), 
		tb
	)
);
-Jarmo
JanneI
Level III

Re: Nested loops with List boxes

Hello,

 

Jim: Thanks for your solution. It works well. I see now why my trials were not successful.

Jarmo: Thanks for your suggestion for alternative solution to use Table Box or Lineup Box; very educative.

 

Janne

 

Re: Nested loops with List boxes

I wonder if a Line Up Box would be a better approach?