• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Problem with NextTblInDoc

Community Expert ,
Feb 23, 2021 Feb 23, 2021

Copy link to clipboard

Copied

  • 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...

TOPICS
Scripting

Views

129

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Feb 23, 2021 Feb 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.

Votes

Translate

Translate
Community Expert ,
Feb 23, 2021 Feb 23, 2021

Copy link to clipboard

Copied

    if (!obj.ObjectValid()) { // end of table ?
      oRow = obj.CellRow;

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 23, 2021 Feb 23, 2021

Copy link to clipboard

Copied

LATEST

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
    }
  }
}

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines