isFound()

Help with writing and running scripts

isFound()

Postby Jaretin » Mon Mar 26, 2007 11:04 am

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?
User avatar
Jaretin
Basic User
Basic User
 
Posts: 19
Joined: Sun Mar 25, 2007 11:00 pm

Re: isFound()

Postby Bego » Mon Mar 26, 2007 2:41 pm

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
User avatar
Bego
Master
Master
 
Posts: 357
Joined: Wed Nov 24, 2004 12:00 am
Location: Germany

Re: isFound()

Postby Jaretin » Mon Mar 26, 2007 4:07 pm

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.
User avatar
Jaretin
Basic User
Basic User
 
Posts: 19
Joined: Sun Mar 25, 2007 11:00 pm

Re: isFound()

Postby Bego » Mon Mar 26, 2007 5:18 pm

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

Am I missing sth. ?
User avatar
Bego
Master
Master
 
Posts: 357
Joined: Wed Nov 24, 2004 12:00 am
Location: Germany

Re: isFound()

Postby Jaretin » Mon Mar 26, 2007 5:25 pm

The thing you miss is, that orgDoc.isFound() returns false although the string is found!
User avatar
Jaretin
Basic User
Basic User
 
Posts: 19
Joined: Sun Mar 25, 2007 11:00 pm

Re: isFound()

Postby Bego » Mon Mar 26, 2007 5:46 pm

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
User avatar
Bego
Master
Master
 
Posts: 357
Joined: Wed Nov 24, 2004 12:00 am
Location: Germany

Re: isFound()

Postby Bego » Fri Apr 13, 2007 11:36 am

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 ...
User avatar
Bego
Master
Master
 
Posts: 357
Joined: Wed Nov 24, 2004 12:00 am
Location: Germany

Re: isFound()

Postby mik0001 » Fri Apr 13, 2007 12:07 pm

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 :-(
User avatar
mik0001
Basic User
Basic User
 
Posts: 37
Joined: Fri Mar 16, 2007 11:00 pm
Location: Germany

Re: isFound()

Postby Bego » Fri Apr 13, 2007 5:30 pm

Hallo mik !

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

Gruss Bego
User avatar
Bego
Master
Master
 
Posts: 357
Joined: Wed Nov 24, 2004 12:00 am
Location: Germany

Re: isFound()

Postby Bego » Wed Apr 18, 2007 5:58 am

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
User avatar
Bego
Master
Master
 
Posts: 357
Joined: Wed Nov 24, 2004 12:00 am
Location: Germany

Re: isFound()

Postby Jaretin » Wed Apr 18, 2007 7:16 am

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?
User avatar
Jaretin
Basic User
Basic User
 
Posts: 19
Joined: Sun Mar 25, 2007 11:00 pm

Re: isFound()

Postby Bego » Wed Apr 18, 2007 8:13 am

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
User avatar
Bego
Master
Master
 
Posts: 357
Joined: Wed Nov 24, 2004 12:00 am
Location: Germany


Return to Scripts

cron