How to tell FIND command to stop searching

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
urbaud
Posts: 120
Joined: Tue Feb 24, 2009 12:10 am

How to tell FIND command to stop searching

Post by urbaud » Tue Oct 16, 2012 5:09 pm

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.
urbaud

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: How to tell FIND command to stop searching

Post by Simon » Tue Oct 16, 2012 5:16 pm

Isn't this just a case of:
if the result <> empty then
---do something

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: How to tell FIND command to stop searching

Post by Klaus » Tue Oct 16, 2012 6:09 pm

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)

urbaud
Posts: 120
Joined: Tue Feb 24, 2009 12:10 am

Re: How to tell FIND command to stop searching

Post by urbaud » Wed Oct 17, 2012 12:24 am

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.
urbaud

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: How to tell FIND command to stop searching

Post by Simon » Fri Oct 19, 2012 7:09 pm

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
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Post Reply