Find variables in appearing order
Dear friends,
Collecting variables in the order of their creation works fine for me:
function GetVarsInDoc (oDoc, aDocVars) { //=== Fill the doc variables array with all found vars in Doc ======
var oTR, oVar, sVarName, sValue;
aDocVars.length = 0; // clear array for new build up
oVar = oDoc.FirstVarInDoc; // the variable in the text
while (oVar.ObjectValid()) {
sVarName = oVar.VarFmt.Name; // name of the variable
sValue = oVar.VarFmt.Fmt; // contents of variable
oTR = oVar.TextRange; // the text range of the variable
aDocVars.push (new oVariable (sVarName, sValue, oVar, oTR));
oVar = oVar.NextVarInDoc;
}
} //--- end GetVarsInDoc
When walking (do you have a better term) through the collected variables the display jumps between body and master pages and the first few variables are all on the master pages. This jumping irritates the user. Hence I want to collect the variables in the order as they appear in the document (will jump only once to the master pages) - same as when using the Find dialogue with Any Variable.
The following, however, does not do anything at all - what is wrong?
function GetVarsInDoc (oDoc, aDocVars) { //=== Collect variables in the 'natural' order ===========
var findParams, oPara, oTRnew TextRange(), oTxtLoc1, oTxtLoc2;
oPara = oDoc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf; // Start at the beginning of the document
oTR.beg.obj = oTR.end.obj = oPara;
oDoc.ScrollToText(oTR); // test - nothing to see
findParams = GetFindParameters (2, null); // Get the find parameters for finding any variable
InitFA_errno (); // reset - it is write protected (function not shown here)
oTR = oDoc.Find(oTR.beg, findParams); // and do an initial find to get started.
while(FA_errno === Constants.FE_Success) {
oDoc.TextSelection = oTR; // set up the text range// here code is required to come from oTR to the variable object for storage
oDoc.ScrollToText(oTR); // test - nothing to see
InitFA_errno (); // to be used to track the progress of the find and replace
oTR = oDoc.Find(oTR.end, findParams); // prepare for next find
}
} //--- end GetVarsInDoc
This is a stripped down version:
function GetFindParameters (iType, sSearch) { //=== set up parameters for various find actions ====
var findParams, propVal;
findParams = new PropVals() ;
switch (iType) {
case 2: // ---------------------------------- find any variable
propVal = new PropVal() ;
propVal.propIdent.num = Constants.FS_FindObject;
propVal.propVal.valType = Constants.FT_Integer;
propVal.propVal.ival = Constants.FV_FindAnyVariable ;
findParams.push(propVal);
return findParams;
default:
return null;
}
} //--- end GetFindParameters
Who can give me a hint?
Klaus

