Skip to main content
K.Daube
Community Expert
Community Expert
Dec 4, 2020 10:29 AM UTC
Answered

Find Customisation Flags not accepted

Dear all,

In a previous project the setting of such a flag was successful:

 

 

oPropVal = new PropVal() ;  
oPropVal.propIdent.num = Constants.FS_FindCustomizationFlags ; 
oPropVal.propVal.valType = Constants.FT_Integer;  
oPropVal.propVal.ival = Constants.FF_FIND_BACKWARDS ; 
findParams.push(oPropVal);  

 

 

But now, in a more general set-up the flags are not set:

 

 

if (bWord || bCase || bBack || bRegEx || bWild) { 
  oPropVal3 = new PropVal() ;  
  oPropVal3.propIdent.num = Constants.FS_FindCustomizationFlags ;  
  oPropVal3.propVal.valType = Constants.FT_Integer;  
  oPropVal3.propVal.ival = 0;
  if (bCase)  {oPropVal3.propVal.ival  || Constants.FF_FIND_CONSIDER_CASE;}
  if (bRegEx) {oPropVal3.propVal.ival  || Constants.FF_FIND_USE_REGEX;     
  } else {
    if (bWild) {oPropVal3.propVal.ival || Constants.FF_FIND_USE_WILDCARDS;}
    if (bWord) {oPropVal3.propVal.ival || Constants.FF_FIND_WHOLE_WORD;}   
    if (bBack) {oPropVal3.propVal.ival || Constants.FF_FIND_BACKWARDS;}    
  }
  findParms.push(oPropVal3);  
}

 

 

A break point prior to FindParms.push (oPropVal3) and inspection of the object tells me that ival is not sufficiently defined:

What is wrong with my definitions?

Wait a minute

Just now here in the browser the view on the subject is different: there are no = assignments...

This topic is closed to new replies. Start a new post to keep the conversation going.
K.Daube
K.DaubeCorrect answer
Community Expert
Dec 9, 2020 11:36 AM UTC

I have now shrinked the script to the (what I think) bare minimum:

 

 

/* Test_GetFindParameters.jsx ====== UTF-8 ================================
              Test for the functions GetFindParameters, FindSomething
History       2020-12-05 test with VSCode and ESDebugger
*/ ; // ==================================================================

//@target framemaker
var KLD_Z = KLD_Z || {};                          // global script object

KLD_Z.GetFindParameters = function (sSearch) { //====
//           Set up a text find with case sensitive RegEx
var bRegEx, findParms, qFlags, oPropVal1, oPropVal2, oPropVal3; 
  findParms = new PropVals();
  oPropVal1 = new PropVal() ;  
    oPropVal1.propIdent.num = Constants.FS_FindText;  
    oPropVal1.propVal.valType = Constants.FT_String;  
    oPropVal1.propVal.sval = sSearch;  
  findParms.push(oPropVal1);  

  oPropVal2 = new PropVal() ;  
    oPropVal2.propIdent.num = Constants.FS_FindCustomizationFlags ;  
    oPropVal2.propVal.valType = Constants.FT_Integer; 
    qFlags = 0; 
    qFlags = qFlags   | Constants.FF_FIND_CONSIDER_CASE; // 0x01
    qFlags = qFlags   | Constants.FF_FIND_USE_REGEX;     // 0x10
    oPropVal2.propVal.ival = qFlags;                     // 
  findParms.push(oPropVal2);  

  oPropVal3 = new PropVal ();  
    oPropVal3.propIdent.num = Constants.FS_RegexFlavour;  
    oPropVal3.propVal.valType = Constants.FT_Integer;  
    oPropVal3.propVal.ival = Constants.FR_USE_PERL;      // 1
    findParms.push(oPropVal3);  

  $.bp(true);   // check oPropVal2 and oPropVal3
  return findParms;
} //---  end GetFindParameters -------------------------------------------
KLD_Z.FindSomething = function (oDoc, iFS, iFV, sSearch, iMode, bWord, bCase, bBack, bStart) { // ========
//            Find anything defined by the parameters
var oFindParms, oTR, oTRsaved ;
  oTRsaved = oDoc.TextSelection;                  // we may need to come back to the start location
  oTR = oDoc.TextSelection;                       // start from current location
  oFindParms = KLD_Z.GetFindParameters (sSearch); // set up for text search, case sentive RegEx
  oTR = oDoc.Find(oTR.beg, oFindParms);
  if (FA_errno === Constants.FE_Success) {        // 0: FE_Success; -95: FE_NotFound
    return oTR;
  } else {                                        // Not found
    return undefined;
  }
} //---  end FindSomething -----------------------------------------------

KLD_Z.main = function () { // ============================================
// Find text containing  1stxxx 2ndxxx 3rdxxx or 4thxxx 5thxxx ...
var oDoc, OK, oTR;
//$.bp(true);
  oDoc = app.ActiveDoc;
//OK = KLD_Z.FindSomething (oDoc, iFS, iFV, sSearch, iMode, bWord, bCase, bBack);
//$.bp(true);
  oTR = KLD_Z.FindSomething (oDoc, 1, null, "\\d[st|nd|rd|th]", 2, false, false, false); 
  if (oTR == undefined) {
    Alert ("not found");
  }
} //--- end main ---------------------------------------------------------
  
KLD_Z.main ();

 

 

But I still get the same errors when lookink at the properties on the line " $.bp(true); // check oPropVal2 and oPropVal3".

 


Sorry folks, the whole issue is a Hornberger Schiessen (wild goose chase):

The error messages in the Data Browser are irrelevant for the positive result. The script successfully finds 1st, 2nd, 4th and 5th and refuses to find 3Rd - hence RegEx search is OK and Consider Case is observed:

 

/*Test_MiniFind.jsx ====== UTF-8 ==========================================
              Test for the functions GetFindParameters, FindSomething
History       2020-12-09
*/ ; // ===================================================================
//#target framemaker
//@target framemaker

function GetFindParameters (sSearch) { //======================
//           Set up a text find with case sensitive RegEx
var findParms, qFlags, oPropVal1, oPropVal2, oPropVal3; 

  findParms = new PropVals();
  oPropVal1 = new PropVal() ;  
    oPropVal1.propIdent.num = Constants.FS_FindText;  
    oPropVal1.propVal.valType = Constants.FT_String;  
    oPropVal1.propVal.sval = sSearch;  
  findParms.push(oPropVal1);  

  oPropVal2 = new PropVal() ;  
    oPropVal2.propIdent.num = Constants.FS_FindCustomizationFlags ;  
    oPropVal2.propVal.valType = Constants.FT_Integer; 
    qFlags = 0; 
    qFlags = qFlags   | Constants.FF_FIND_CONSIDER_CASE; // 0x01
    qFlags = qFlags   | Constants.FF_FIND_USE_REGEX;     // 0x10
    oPropVal2.propVal.ival = qFlags;                     // 
  findParms.push(oPropVal2);  

  oPropVal3 = new PropVal ();  
    oPropVal3.propIdent.num = Constants.FS_RegexFlavour;  
    oPropVal3.propVal.valType = Constants.FT_Integer;  
    oPropVal3.propVal.ival = Constants.FR_USE_PERL;      // 1
    findParms.push(oPropVal3);  

//$.bp(true);   // check oPropVal2 and oPropVal3 - ival reports errors...
  return findParms;
} //---  end GetFindParameters -------------------------------------------------

function FindSomething (oDoc, sSearch) { // ===============================
var oFindParms, oTR, oTRsaved ;

  oTRsaved = oDoc.TextSelection;                  // we may need to come back
  oTR = oDoc.TextSelection;                       // start from current location

  oFindParms = GetFindParameters (sSearch); 
  if (oFindParms === null) {return undefined;}    // oTR has not changed yet
  oTR = oDoc.Find(oTR.beg, oFindParms);
  if (FA_errno === Constants.FE_Success) {        // 0: FE_Success; -95: FE_NotFound
    oDoc.TextSelection = oTR;                     // selection visible ? 
    oDoc.ScrollToText(oTR);                       // selection visible ? Yes
    return oTR;
  } else {                                        // Not found
    oDoc.TextSelection = oTRsaved;
    oDoc.ScrollToText(oTRsaved);
    return undefined;
  }
} //---  end FindSomething ------------------------------------------------

function main () { // =====================================================
// testfile: E:\_DDDprojects\_JSX-library\TestFiles\Gugus-file1.fm 
//           ontains 1st, 2nd, 3Rd, 4th, 5th 
var oDoc = app.ActiveDoc, OK, oTR;

 oTR = FindSomething (oDoc, "\\d[st|nd|rd|th]");  // text by regex

if (oTR == undefined) {
    Alert ("not found");
  }
} //--- end main ----------------------------------------------------------

main ();

 

 I do not know yet why my initial script did not work - have to take a very close look to the differences to this working script.

7 replies

K.Daube
Community Expert
K.DaubeCommunity ExpertAuthor
Community Expert
Dec 4, 2020 10:38 AM UTC

Huch, can not delete this

Translate
K.Daube
Community Expert
K.DaubeCommunity ExpertAuthor
Community Expert
Dec 4, 2020 10:45 AM UTC

It must look like this

 

 

if (bWord || bCase || bBack || bRegEx || bWild) { // customisation flags are ORED
  oPropVal3 = new PropVal() ;  
  oPropVal3.propIdent.num = Constants.FS_FindCustomizationFlags ;  
  oPropVal3.propVal.valType = Constants.FT_Integer; 
  ival3 = 0; 
  if (bCase)  { ival3 = ival3   || Constants.FF_FIND_CONSIDER_CASE;}                       // 0x01
  if (bRegEx) { ival3 = ival3   || Constants.FF_FIND_USE_REGEX;                            // 0x10
  } else {
    if (bWild)  { ival3 = ival3 || Constants.FF_FIND_USE_WILDCARDS;}  // 0x04
    if (bWord)  { ival3 = ival3 || Constants.FF_FIND_WHOLE_WORD;}     // 0x02
    if (bBack)  { ival3 = ival3 || Constants.FF_FIND_BACKWARDS;}      // 0x08
  }
  oPropVal3.propVal.ival = ival3;
  findParms.push(oPropVal3);  
}

 

But this does not help!

I still have this «ssval does not have a value»

 

Translate
frameexpert
Community Expert
Community Expert
Dec 4, 2020 12:52 PM UTC

Hi Klaus,

When you OR flags together, you use a single pipe | character. For example, here is a function where I am getting Import Formats settings:

GS_ANT.getImportFormatsFlags = function (settings) {
    
    var flags = 0;
    
    // Paragraph formats.
    flags = flags | Constants.FF_UFF_PGF;
    // Character formats.
    flags = flags | Constants.FF_UFF_FONT;
    // Table formats.
    flags = flags | Constants.FF_UFF_TABLE;
    // Page layouts.
    flags = flags | Constants.FF_UFF_PAGE;
    // Reference pages.
    flags = flags | Constants.FF_UFF_REFPAGE;
    // Colors.
    flags = flags | Constants.FF_UFF_COLOR;
    // Combined fonts.
    flags = flags | Constants.FF_UFF_COMBINED_FONTS;
    // Conditional text settings.
    flags = flags | Constants.FF_UFF_COND;
    // Math settings.
    flags = flags | Constants.FF_UFF_MATH;
    // Cross-reference formats.
    flags = flags | Constants.FF_UFF_XREF;
    // Filter by attributes settings.
    flags = flags | Constants.FF_UFF_FBA;
    // Object styles.
    flags = flags | 0x2000;
    // Page breaks.
    flags = flags | Constants.FF_UFF_REMOVE_PAGE_BREAKS;
    // Format overrides.
    flags = flags | Constants.FF_UFF_REMOVE_EXCEPTIONS; 
    
    return flags;
};
Translate
www.frameexpert.com