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

JSL script help

This is related to the partition script, I am trying to save the selected and unselected rows as different tables after partition function. But when I do that the whole JSL script goes into an infinite loop. Is there any way to solve this?

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: JSL script help

I would guess it goes into infinite loop because you make new selection of rows inside the row state handler (invert row selection). You could try to avoid selection of rows by using the parameter a  you have already in the function (it should tell the rows which had states changed) with some idea of this:

 

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/big class.jmp");

tableCount = 0;
theRows = [];
filepath = "$Desktop";

f = Function({a}, 
	// Set dupRows to the previously selected rows
	dupRows = theRows;
	// Get the current selected rows
	theRows = a;
	If(N Rows(theRows) > 0, 
		// check to see if there are the same number of rows
		// then validate the rows are different rows before saving
		If(N Rows(theRows) == N Rows(dupRows),
			If(Sum(dupRows == theRows) != N Rows(theRows),
				tableCount++;
				dtTemp = dt << subset(invisible, rows(theRows), selected columns(0));
				dtSEG = dt << subset(rows(dupRows), selected columns(0));
				Close(dtTemp, save(filepath || "\" || "part" || ".jmp"));
				Close(dtSEG, save(filepath || "\" || "seg2" || ".jmp"));
			)
		, 
			// If not the same number of selected rows, save the subset
			tableCount++;
			dtTemp = dt << subset(invisible, rows(theRows), selected columns(0));
			dtSEG = dt << subset(rows(dupRows), selected columns(0));
			Close(dtTemp, save(filepath || "\" || "part" || Char(tableCount) || ".jmp"));
			Close(dtSEG, save(filepath || "\" || "seg2" || Char(tableCount) || ".jmp"));
		)
	);
	Show(a, tableCount); //debug print
);

rs = Current Data Table() << make row state handler(f);

I would most likely avoid row state handler and use some sort of new window in which user can press a button when selections have been done. This is because I have had a fair bit of issues with Row State Handlers and try to avoid them whenever possible.

 

 

 

-Jarmo

View solution in original post

2 REPLIES 2
jthi
Super User

Re: JSL script help

I would guess it goes into infinite loop because you make new selection of rows inside the row state handler (invert row selection). You could try to avoid selection of rows by using the parameter a  you have already in the function (it should tell the rows which had states changed) with some idea of this:

 

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/big class.jmp");

tableCount = 0;
theRows = [];
filepath = "$Desktop";

f = Function({a}, 
	// Set dupRows to the previously selected rows
	dupRows = theRows;
	// Get the current selected rows
	theRows = a;
	If(N Rows(theRows) > 0, 
		// check to see if there are the same number of rows
		// then validate the rows are different rows before saving
		If(N Rows(theRows) == N Rows(dupRows),
			If(Sum(dupRows == theRows) != N Rows(theRows),
				tableCount++;
				dtTemp = dt << subset(invisible, rows(theRows), selected columns(0));
				dtSEG = dt << subset(rows(dupRows), selected columns(0));
				Close(dtTemp, save(filepath || "\" || "part" || ".jmp"));
				Close(dtSEG, save(filepath || "\" || "seg2" || ".jmp"));
			)
		, 
			// If not the same number of selected rows, save the subset
			tableCount++;
			dtTemp = dt << subset(invisible, rows(theRows), selected columns(0));
			dtSEG = dt << subset(rows(dupRows), selected columns(0));
			Close(dtTemp, save(filepath || "\" || "part" || Char(tableCount) || ".jmp"));
			Close(dtSEG, save(filepath || "\" || "seg2" || Char(tableCount) || ".jmp"));
		)
	);
	Show(a, tableCount); //debug print
);

rs = Current Data Table() << make row state handler(f);

I would most likely avoid row state handler and use some sort of new window in which user can press a button when selections have been done. This is because I have had a fair bit of issues with Row State Handlers and try to avoid them whenever possible.

 

 

 

-Jarmo
shasha_2
Level III

Re: JSL script help

Thank you for the help. Now, it is working properly, I have removed the row state handler and used a function which is called on close of the window. This does the creation of two subsets.