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