Skip to main content
dublove
Brainiac
January 1, 2025
Question

Dead Loop? How do I jump out and why do I get two results for the same text box?

  • January 1, 2025
  • 1 reply
  • 531 views

What I'm thinking of is determining if the last row is empty.
If it's empty, set it to footer.
If it's not empty, add one empty row at the end and set the empty row to footer.

 

When you don't expand the text box, it says “empty”. (This is actually wrong.)

When you expand the box, it says “not empty” again.

 

I'm a little confused about functions, methods, and objects.
Also, if you take out the Break, it becomes a dead loop?
How do I get the code after it to run?

 

Please guide me.

Thank you very much.

See attachment for sample. 

“alter” is used for testing. Can be deleted

 

 

 

 

var cell = app.activeDocument.selection[0].parent;
var myTable = cell.parent;

var myFooterRow = myTable.rows[-1];
dupeLastRow(myTable);

function dupeLastRow(p){
	
	var isLastRowEmpty = true;
	for (var j = 0; j < myFooterRow.cells.length; j++) {
		if (myFooterRow.cells[j].contents !== "") {
			isLastRowEmpty = false;
			alert("No-empty");
			break;
		}
		else{
			isLastRowEmpty = true;
			alert("empty");
				break;
		}
	}
	if(isLastRowEmpty = false){
		myTable.rows.add(LocationOptions.AFTER, myTable.rows[-1]);
		myFooterRow = myTable.rows[-1];
	}
	else{
		isLastRowEmpty = true;
		myFooterRow = myTable.rows[-1];
	}
	}

 

 

 

 

1 reply

Robert at ID-Tasker
Brainiac
January 1, 2025

Invisible cells - cells that are in the overset text - your 1st table in the screenshot - or cells that are completely overset - no text inside, just red dot - do not have any contents. 

 

So your if should be:

 

 

    if (myFooterRow.cells[j].texts[0].contents !== "") {

 

dublove
dubloveAuthor
Brainiac
January 2, 2025

Thnak you.

The judgment seems to be right, for some reason the last "if else" doesn't run

I've deleted break.

dublove
dubloveAuthor
Brainiac
January 2, 2025
Oh, I think so.
isLastRowEmpty = false
Should be isLastRowEmpty == false