Creating a Search Field

Gregory Lypny gregory.lypny at videotron.ca
Sat Apr 26 12:25:50 EDT 2008


Hello everyone,

I tried to write a handler for one of those nifty search fields that  
you find in Mac programs like Mail, where it pulls up found records as  
you type a search phrase.  I came up with the following.   
(Incidentally, I do not use the filter command because it is much  
slower than "repeat for each" on big data sets.)

on keyDown
   put me into searchString
   get fld "Data"
   repeat for each line thisLine in it
     if thisLine contains searchString then put thisLine & return  
after hits
   end repeat
   if the last character of hits is return then delete the last  
character of hits
   put hits into fld "Browse List"
   put "Found" && recordCount(hits,"f") into fld "Number of Records"   
-- a hit count function
   pass keyDown
end keyDown

It does the trick, but has a number of glitches that I'd like to fix.   
The main one is that it pulls up records that do not contain the  
search string.  For example, if I type "mit" (without quotes), it will  
correctly pull up records that contain Mitchell; however, if I then  
type another letter, say "p", it will still pull up the same records  
that contain Mitchell even though none of these has the string "mitp",  
although some do contain "mit" in one spot and somewhere else a "p"  
and others do not contain "p" at all.  I must not be understanding the  
contains operator.

The other thing that tells me I haven't gotten it right is that the  
hit list should get smaller the more characters I type and bigger as I  
delete them.  Well, most of the time the first character I type (e.g.,  
just an "m") turns up nothing; I have to type a second character to  
get it going.  And keyDown does not seem to respond to the Delete key.

Any suggestions would be most appreciated.

Gregory



More information about the use-livecode mailing list