isFound()

isFound()

21
Basic UserBasic User
21

    Mar 26, 2007#1

    Hello,

    i'm using 13v+4 in the german version.

    And isFound() doesn't work.
    ...
    I use the following Source:

    var orgDoc = UltraEdit.document[j];
    orgDoc.columnModeOff;
    orgDoc.top();
    orgDoc.findReplace.regExp = false;
    orgDoc.findReplace.matchWord = false;
    orgDoc.findReplace.matchCase = false;
    orgDoc.findReplace.searchDown = true;
    orgDoc.findReplace.matchWord = false;
    orgDoc.findReplace.find("<?xml");

    if ( orgDoc.isFound() ) {
    UltraEdit.getString("isFound",1);
    }
    else {
    UltraEdit.getString("Not isFound",1);
    }

    var found = orgDoc.selection == "<?xml";

    I got "Not isFound" but the variable found is true.
    Is this an error or should i use isFound in a different way?

    344
    MasterMaster
    344

      Mar 26, 2007#2

      I don't know what your strange code should do.
      The read-only property .selection means:
      Returns currently selected text. Example:

      var text = UltraEdit.activeDocument.selection;
      Well, you already have a if-switch to check if you found sth. or not. It works.

      Your line

      Code: Select all

      var found = orgDoc.selection == "<?xml";
      is very strange then...

      Bego
      Normally using all newest english version incl. each hotfix. Win 10 64 bit

      21
      Basic UserBasic User
      21

        Mar 26, 2007#3

        The code just checks if the searched String is selected in the document.

        For better understanding.

        if ( orgDoc.selection == "<?xml" ) {
        found = true;
        }
        else {
        found = false;
        }

        This is what isFound() should do.

        344
        MasterMaster
        344

          Mar 26, 2007#4

          but if it is found, it is automatically selected.
          If not, then not.

          Am I missing sth. ?
          Normally using all newest english version incl. each hotfix. Win 10 64 bit

          21
          Basic UserBasic User
          21

            Mar 26, 2007#5

            The thing you miss is, that orgDoc.isFound() returns false although the string is found!

            344
            MasterMaster
            344

              Mar 26, 2007#6

              OK, now I see. I made an own example and had the same problem. 13+4

              Code: Select all

              //let this script run on a file with one line that looks like this:
              //The isFound in UE 13+4 works bad I think
              
              var orgDoc = UltraEdit.document[0];
              orgDoc.columnModeOff;
              orgDoc.top();
              orgDoc.findReplace.regExp = false;
              orgDoc.findReplace.matchWord = false;
              orgDoc.findReplace.matchCase = false;
              orgDoc.findReplace.searchDown = true;
              orgDoc.findReplace.matchWord = false;
              orgDoc.findReplace.find("works");
              
              if ( orgDoc.isFound() ) {
              UltraEdit.getString(" works is found (as expected)",1);
              }
              else {
              UltraEdit.getString("works is NOT found",1);
              }
              
              orgDoc.top();
              orgDoc.findReplace.find("lalala");
              if ( orgDoc.isFound() ) {
              UltraEdit.getString(" lalala is found :-/",1);
              }
              else {
              UltraEdit.getString("lalala is NOT found (as expected)",1);
              }
              
              Pls write a bug-report to IDM and post a ref to this thread.

              rds Bego

                Apr 13, 2007#7

                Still not working in 13.00a :-(

                There are some things in the script-corner that make me think "Did they ever write one single script ?".
                Still I don't know why a closeFile needs a parameter ....
                It also might be a good thing to know whether a search had success or not ... It blocks my whole scripting development here :-/

                Any news from your side, Jaretin ?

                Anyway, lets wait ...
                Normally using all newest english version incl. each hotfix. Win 10 64 bit

                30
                Basic UserBasic User
                30

                  Apr 13, 2007#8

                  1. I changed the code into this:

                  -----
                  var orgDoc = UltraEdit.document[0];

                  orgDoc.top();

                  if ( orgDoc.findReplace.find("lalala") ) {
                  UltraEdit.getString(" lalala is found :-)",1);
                  }
                  else {
                  UltraEdit.getString("lalala is NOT found :-(",1);
                  }
                  -----

                  In my case it works (v13.00a).

                  2. "orgDoc.closeFile" does not work here, too :-(

                  344
                  MasterMaster
                  344

                    Apr 13, 2007#9

                    Hallo mik !

                    1. OK, seems we have to directly check the find's RC. Thx.

                    Gruss Bego

                      Apr 18, 2007#10

                      Hi Mik (and everybody else),

                      I try a find in a loop and get a strange behaviour (UE13.00a).
                      If I have a textfile like this:
                      lala = abc
                      lala = def
                      lala = ghi
                      lala = jkl
                      and a code like this:

                      Code: Select all

                      var orgDoc;
                      
                      UltraEdit.activeDocument.copy();
                      UltraEdit.newFile();
                      orgDoc = UltraEdit.activeDocument;
                      orgDoc.paste();
                      orgDoc.top();
                      
                      
                      //this one positions cursor at line 3, it works.
                      //UltraEdit.activeDocument.findReplace.find("lala");
                      //UltraEdit.activeDocument.findReplace.find("lala");
                      //UltraEdit.activeDocument.findReplace.find("lala");
                      
                      //This one is strange
                      var i = 0;
                      while (true) {
                        if  (orgDoc.findReplace.find("lala") ) {
                            i++;
                        }
                        else
                        {
                           break;
                        }
                      }
                      UltraEdit.document[1].write("Found that many times: " + String(i));
                      I get this result in a new document:

                      Code: Select all

                      Found that many times: 1 = abc
                      I expected:

                      Code: Select all

                      Found that many times: 4
                      (without the abc(!))

                      Is this my error ?

                      Thx, Bego
                      Normally using all newest english version incl. each hotfix. Win 10 64 bit

                      21
                      Basic UserBasic User
                      21

                        Apr 18, 2007#11

                        This works.

                        Code: Select all

                        var orgDoc;
                        
                        orgDoc = UltraEdit.activeDocument;
                        orgDoc.top();
                        
                        var i = 0;
                        while (orgDoc.findReplace.find("lala")) {
                        	i++;
                        }
                        UltraEdit.getString("Found that many times: " + String(i),1);
                        
                        Don't know, what you are doing with the copy?

                        344
                        MasterMaster
                        344

                          Apr 18, 2007#12

                          Hi Jaretin,

                          I try to write a js-macro that auto-aligns (with spaces) assignments.
                          e.g.

                          Code: Select all

                          nospaces = 123;
                              somespaces =    456;
                            
                          to sth. like this:

                          Code: Select all

                          nospaces   = 123;
                          somespaces = 456;
                            
                          Plan: Mark those n lines with the mouse. Then the Macro does the following: Move the lines to a new doc, manipluate them and repaste the lines to the source-doc.

                          the problem that I had: I did not mark those lines, so I had only 1 hit :oops: So my code should run too if you mark some lines.
                          Thx anyway !

                          If somebody has already a solution/tips for my problem, pls post.

                          rds Bego
                          Normally using all newest english version incl. each hotfix. Win 10 64 bit