Hello all. have been playing with this for days and can't get it working in a smooth fashion. I have a text box that will contain a few paragraphs of text. I have a list of about 400 words and want to perform a find on each of these words with a buttons mouseUp. Once found I have changed the textColor of the foundText to red. I have it working with an individual word but cant get it to work on multiple words without adding 400 individual find commands. Any suggestions? I have
on mouseUp
repeat until found empty
find word "cat" in field "myField"
set the textColor of foundText to red
if the result is not empty then
exit to top
end if
end mouseUp
I want to find cat, dog, mouse etc. with an additional 400 words and turn the found words to red.
Thanks in advance!
Find function
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Re: Find function
First thing to note..
For a repeat block you need "repeat until condition"
and "end repeat" Gotta have the end repeat or there will be problems though i'm assuming its just a typo.
Then, if you have a list of words you can cycle through each word and mark them as needed.
Also, repeat until loops are easy to hang. During testing and development its not a bad idea to give yourself an easy out.
Something like "If the shiftkey is down then exit to top" will work. That way if you have a runaway loop, just hold down shift till it exits. (the code for this has to be inside the loop you want to exit of course.
For a repeat block you need "repeat until condition"
and "end repeat" Gotta have the end repeat or there will be problems though i'm assuming its just a typo.
Then, if you have a list of words you can cycle through each word and mark them as needed.
Code: Select all
on mouseUp
put "dog,horse,pig,geese,goose" into tWords
repeat for each item tItem in tWords --repeat for each item (comma is default item delimiter)
-- the repeat places each item into the temporary varaible tItem for use in the script
find empty -- make sure find is starting fresh
put false into tExit -- var used to exit internal loop
repeat until tExit -- if tExit is true then the loop will exit.
find words tItem in field 1 -- do the find
if the foundChunk is empty then -- if nothing was found, change tExit to true. Used to exit internal loop.
put true into tExit
else -- else change the color of the text in the found chunk (a chunk being a description of where the text is)
set the textcolor of the foundchunk to red
end if
end repeat
end repeat
end mouseUp
Also, repeat until loops are easy to hang. During testing and development its not a bad idea to give yourself an easy out.
Something like "If the shiftkey is down then exit to top" will work. That way if you have a runaway loop, just hold down shift till it exits. (the code for this has to be inside the loop you want to exit of course.
-
- Posts: 23
- Joined: Sun Mar 03, 2013 1:09 am
Re: Find function
Amazing community here. Thanks so much for the help!
Re: Find function
You might want to put a lock screen and unlock screen around your repeat loop also (if you don't care about seeing the find box jumping around in the field) it will make the response time for the search MUCH faster if the screen doesn't need to be updated till completion.
end mouseUp
Code: Select all
on mouseUp
put "dog,horse,pig,geese,goose" into tWords
lock screen -- begin the lock
repeat for each item tItem in tWords --repeat for each item (comma is default item delimiter)
-- the repeat places each item into the temporary varaible tItem for use in the script
find empty -- make sure find is starting fresh
put false into tExit -- var used to exit internal loop
repeat until tExit -- if tExit is true then the loop will exit.
find words tItem in field 1 -- do the find
if the foundChunk is empty then -- if nothing was found, change tExit to true. Used to exit internal loop.
put true into tExit
else -- else change the color of the text in the found chunk (a chunk being a description of where the text is)
set the textcolor of the foundchunk to red
end if
end repeat
end repeat
unlock screen -- end the lock
-
- Posts: 23
- Joined: Sun Mar 03, 2013 1:09 am
Re: Find function
Ah, yes. that sped it up greatly. It is working fabulously. Thanks again!