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

Eric Chatonet eric.chatonet at sosmartsoftware.com
Sat Feb 4 10:59:37 EST 2006


Re André,

Le 4 févr. 06 à 16:45, André.Bisseret a écrit :

> Le Saturday, 4 Feb 2006, à 15:34 Europe/Paris, Eric Chatonet a écrit :
>
>> 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 :-)
> Bonjour Éric,
> I am really sorry, but I don't catch what you are suggesting to me  
> by that first sentence ; where should I have had a look to find how  
> this problem is handled in the IDE? I get the feeling that I am  
> missing some information source !?

YES!
As you know it the IDE is built with Rev.
THIS is of great value: it means that you can modify it and first  
study it :-)
To access all IDE scripts, check the "Contextual menus work  in  
Revolution windows" in the General pane of the Preferences.
Then use a right/control click to open this world :-)

>> For your convenience:
>>
>> function FindNext pDoSelect -- returns a boolean according to a  
>> successful next find
> Anyway thanks a lot for the function ; I am going to study it  
> before choosing (likely more "pro" than my handler, but it is a bit  
> complex isnt' it ?)

It's very complete but you can simplify it:

local lDidFind,lStartChar
-----
function FindNext pDoSelect -- returns a boolean according to a  
successful next find
   local tNotFound,tOffset,tOChar
   -----
   put false into lDidFind
   put true into tNotFound
   -----
   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
   end repeat
   if pDoSelect then
     select char lStartChar to (lStartChar + the length of field  
"find" - 1) of field "Result"
   end if
   put true into lDidFind
   return true
end FindNext

Sorry: I forgot the two local script variables in my previous post
Here field "Result" is the searched field and field "Find" contains  
the string to find.
And the function is used in a handler as the following:

on MakeMySearch -- mouseUp in a button, etc.
   if not FindNext(true) then beep
end MakeMySearch

Best Regards from Paris,
Eric Chatonet
------------------------------------------------------------------------ 
----------------------
http://www.sosmartsoftware.com/    eric.chatonet at sosmartsoftware.com/





More information about the use-livecode mailing list