Skip to main content
K.Daube
Community Expert
Community Expert
February 23, 2021
Answered

Problem with NextTblInDoc

  • February 23, 2021
  • 1 reply
  • 219 views
  • Dear friends,
    My test document has no reference pages, only master and body pages. There are 5 tables on the body pages.
  • The first table is 2 x 2 and in cell 1 the background is magenta (which is what is checked for).
  • This cell is found
  • Re-entering the while-loop after changing obj to obj.NextCellInTbl lets it run to the end of the table
  • This is detected and the script should enter the first cell of the next table for further search.
  • The log lists this:
«Table #1»        cell 1 which was found
«Table #1»        cell skipped 
«Table #1»        cell skipped
«Table #1»        last cell in table
«»                next "table"

This is not the complete script, just the relevant parts.

obj = oDoc.FirstTblInDoc.FirstRowInTbl.FirstCellInRow;
while (obj.ObjectValid()) {
  $.writeln("«" + obj.CellRow.RowTbl.UserString + "»");
  if (CompareColour(obj.CellOverrideShading, kReserved, sColour)) {
    break;
  } else {
    obj = obj.NextCellInTbl;
    if (!obj.ObjectValid()) { // end of table ?
      oRow = obj.CellRow;
      oTbl = oRow.RowTbl.NextTblInDoc; // look for next table
      $.writeln("«" + obj.CellRow.RowTbl.UserString + "»");
      if (oTbl.ObjectValid()) {
        obj = oTbl.FirstRowInTbl.FirstCellInRow;
        continue; // restart search for relevant cell
      }
    }
  }
}

Why do I not enter the second table?

And BTW there is no non-scripted method to set the user string...

This topic has been closed for replies.
Correct answer frameexpert
    if (!obj.ObjectValid()) { // end of table ?
      oRow = obj.CellRow;

If obj is no longer valid (first line) then the second line won't work.

1 reply

frameexpert
Community Expert
frameexpertCommunity ExpertCorrect answer
Community Expert
February 23, 2021
    if (!obj.ObjectValid()) { // end of table ?
      oRow = obj.CellRow;

If obj is no longer valid (first line) then the second line won't work.

K.Daube
Community Expert
K.DaubeCommunity ExpertAuthor
Community Expert
February 23, 2021

Thanks Rick,

Yes, by the time I became blind at least on one eye...

This seems to work as expected:

while (obj.ObjectValid()) {
  if (CompareColour(obj.CellOverrideShading, kReserved, sColour)) {
    break;
  } else {
    oRow = obj.CellRow;
    oTbl = oRow.RowTbl.NextTblInDoc;          // look for next table prophylactivally
    if (obj.NextCellInTbl.ObjectValid()) {
      obj = obj.NextCellInTbl;
    } else {                                  // need go to next table
      obj = oTbl.FirstRowInTbl.FirstCellInRow;// restart search for relevant cell
    }
  }
}