Re: How to stay on a card when repeating a « find »

Eric Chatonet eric.chatonet at sosmartsoftware.com
Sat Feb 4 09:34:35 EST 2006


Bonjour André,

You could have a look at the way by which this problem is handled in  
the IDE (searching in a script): the answer is there :-)
For your convenience:

function FindNext pDoSelect -- returns a boolean according to a  
successful next find
   local  
tTerminators,tCaseSensitive,tFirstSkip,tOcs,tOffset,tNotFound,tOChar
   -----
   put false into lDidFind
   set the hScroll of fld "Result" to 0
   put quote & ",. <>:;$&[]\|()*^%#@!" & cr into tTerminators
   put the caseSensitive into tCaseSensitive
   set the caseSensitive to false
   put true into tNotFound
   if word 1 of fld "Result" <> "Index" then put 0 into tFirstSkip
   else put the number of chars of line 1 to lineOffset 
("              ",fld "result") of fld "Result" into tFirstSkip
   if lStartChar = empty then put 0 into lStartChar
   repeat while tNotFound
     put offset(field "Find", field "Result", lStartChar) into tOffset
     if tOffset is 0 and lStartChar is not 0 then
       put offset(field "Find", field "Result") into tOffset
       if tOffset >= lStartChar then put 0 into tOffset
       put 0 into lStartChar
       beep
     end if
     add tOffset to lStartChar
     if tOffset is 0 or lStartChar is tOChar then return false
     if tOChar is empty then put lStartChar into tOChar
     if the uHilite of button "WholeWord" then
       if char (lStartChar - 1) of field "result" is in tTerminators  
and char (lStartChar + the length of field "find") of field "Result"  
is in tTerminators then
         put false into tNotFound
       end if
     else
       put false into tNotFound
     end if
   end repeat
   if pDoSelect then
     if lStartChar < tFirstSkip then
       set the caseSensitive to tCaseSensitive
       get FindNext(true)
     else select char lStartChar to (lStartChar + the length of field  
"find" - 1) of field "Result"
   end if
   put true into lDidFind
   set the caseSensitive to tCaseSensitive
   return true
end FindNext

Best Regards from Paris,
Eric Chatonet

Le 4 févr. 06 à 15:29, André.Bisseret a écrit :

> I have a background field that displays different texts on the  
> different cards of the background.
> I need to find all the occurrences of one word (or string) on one  
> card only, in order to highlight each occurrence (set the  
> backgroundColor).
> So, when there is no more occurrence of a word on the current card,  
> I must prevent the find to proceed on following cards.
> Here is my current solution :
> ----------------
> on highlightString thisCard
> Global myWords -- several words or strings separated by commas
>   put the name of this cd into currentCard
>   repeat for each item i in myWords
>     repeat
>       find whole i
>       if the name of this cd is currentCard then
>         set the backgroundColor of the foundText to "Burlywood1"
>       else
>         go to currentCard
>         exit repeat
>       end if
>     end repeat
>   end repeat
> end highlightString
> ------------------
> Seems to work but not very nice ! because each time the "find"  
> proceeds to another card I must « lead it back » to the right card  
> (« go to currentCard »).
>
> It seems to me that using « offset » would lead to a rather heavy  
> handler  :-((

------------------------------------------------------------------------ 
----------------------
http://www.sosmartsoftware.com/    eric.chatonet at sosmartsoftware.com/





More information about the use-livecode mailing list