How to tell FIND command to stop searching
Posted: 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.
The Clear text handler is below. It allows the user to clear the highlighted text.
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.
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
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