Page 1 of 1

How to tell FIND command to stop searching

Posted: Tue Oct 16, 2012 5:09 pm
by urbaud
I have a program with one text field that contains several paragraphs of text and another field that allows the user to enter a text string which the program then searches the larger body of text for each instance of it. When an instance of the string is found it is highlighted in yellow. Below is the search handler.

Code: Select all

global searchText
on mouseUp
   select before text of fld "t1"
   put fld "t2" into searchText
   repeat with i = 1 to the number of words in fld "t1"
      find chars searchText in fld "t1"
      set the backgroundcolor of the foundchunk to "yellow"
   end repeat
end mouseUp
The Clear text handler is below. It allows the user to clear the highlighted text.

Code: Select all

global searchText
on mouseUp
   repeat with i = 1 to the number of words in fld "t1"
      set the backgroundcolor of word i in fld "t1" to "white"
   end repeat
end mouseUp
The find command readily finds the text strings and highlights them, but then when the find command finds no further instances of the text string an error message occurs which reads: "Chunk: no target found." I have tried to figure out the code to eliminate getting the error message to no avail. Any help with this problem would be greatly appreciated.

Re: How to tell FIND command to stop searching

Posted: Tue Oct 16, 2012 5:16 pm
by Simon
Isn't this just a case of:
if the result <> empty then
---do something

Simon

Re: How to tell FIND command to stop searching

Posted: Tue Oct 16, 2012 6:09 pm
by Klaus
Simon wrote:Isn't this just a case of:
if the result <> empty then
---do something
Simon
EX-ACTLY! Just like the dictionary says :D

I always wonder why noone seems to take a look at the docs before posting a quesion here,
the docs ain't THAT bad really... 8)

Re: How to tell FIND command to stop searching

Posted: Wed Oct 17, 2012 12:24 am
by urbaud
Hi Simon and Klaus,

Thank you both for responding to my post. I want you to know that I did read the docs regarding the Find command, but the wording: "If the text is not found in the stack, the result function returns "Not found"" didn't mean anything to me at the time; I just didn't clue in at the time about what it was saying. And, I admit, I did not read the docs about the Result function. However, I did read both after you responded and I did get it to work using your suggestions. So, thanks again for the help.

Re: How to tell FIND command to stop searching

Posted: Fri Oct 19, 2012 7:09 pm
by Simon
Hey Klaus,
I remember the docs problem:
If your desk is next to the copy machine, people will first ask you how to use it before reading the documentation.

Not saying this applies to this case, it just happens.

Simon