Endless Loop When Searching Documents in Framemaker
I build an array of acronyms in the document's acronym glossary and use the getFind function below to search the document to see if the acronym is used and how many times it's used (findCtr++). I'm running into some cases where the getFind function goes into an endless loop looking for specific words in specific documents. This might happen with just four words in a document, or sometimes dozens of words. The loop is 100% repeatable. I believe I need to move the textRange.beg to the end of the "find" word each time a match is found, but I'm not familiar enough with ranges to know how to do it. Appreciate any suggestions.
function getFind(findString, considerCase, docName) {
doc=app.ActiveDoc; //sets the active document as the object
docStart = doc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;
textRange = app.ActiveDoc.TextSelection;
findParams = AllocatePropVals (5);
propVal = new PropVal ();
propVal.propIdent.num = Constants.FS_FindText;
propVal.propVal.valType = Constants.FT_String;
propVal.propVal.sval = findString;
findParams[0] = propVal;
propVal = new PropVal ();
propVal.propIdent.num = Constants.FS_FindCustomizationFlags;
propVal.propVal.valType = Constants.FT_Integer;
if (considerCase) {
propVal.propVal.ival = Constants.FF_FIND_CONSIDER_CASE;
} else {
propVal.propVal.ival = 0; }
findParams[1] = propVal;
propVal = new PropVal ();
propVal.propIdent.num = Constants.FS_FindCustomizationFlags;
propVal.propVal.valType = Constants.FT_Integer;
propVal.propVal.ival = 16; // Regular expressions (per RQ)
findParams[2] = propVal;
propVal = new PropVal ();
propVal.propIdent.num = Constants.FS_FindWrap;
propVal.propVal.valType = Constants.FT_Integer;
propVal.propVal.ival=0;
findParams[3] = propVal;
propVal = new PropVal ();
propVal.propIdent.num = Constants.FS_RegexFlavour;
propVal.propVal.valType = Constants.FT_Integer;
propVal.propVal.ival = Constants.FR_USE_PERL; //1;
findParams[4] = propVal;
textRange = doc.Find(textRange.beg, findParams);
checkAcronyms();
}
function checkAcronyms() {
while (textRange.beg.obj.ObjectValid() && FA_errno == Constants.FE_Success) {
var find = getText (textRange, doc) // Matching acronym found
if (find.length > 0) {
findCtr++; // Count times word is found
}
textRange = doc.Find(textRange.beg, findParams);
}
return;
}
