Creating a Search Field

Andre.Bisseret Andre.Bisseret at inria.fr
Sun Apr 27 05:44:10 EDT 2008


Hello Gregory,
If I well understand your aim, you could be interested in adapting the  
search device I programmed thanks to very good advices from Éric  
Chatonnet (as always :-)).
By the way, his tutorial "How to Master Users Data in Entry Boxes"  
might interest you; you can find it on his site :
http://www.sosmartsoftware.com/


I have three fields :
- one is the list to be searched in (say "bigList") -- this field  
could have its visible property set to false
- a second is a one line field where the user write what he/she is  
searching for (say "entry")
- the third is a field where the results of the search appears (say,  
"results")

the script of the  field "entry" is as follow :

local mySubList,
---------------------

ON rawkeyUp
    find empty
     REPEAT
       find fld "entry" in fld "bigList" of this cd
       IF the result is "not found" THEN exit repeat
       ELSE
       put value(the foundline) & cr after mySubList
       END IF
     END repeat
     put empty into fld "results"
     put mySubList into fld "results"
     select char 2 to -1 of line 1 of fld "results"
     select after fld "entry"
     put empty into mySubList
END rawkeyUp

ON returnInField
-- here do what you want with the found word
(I use the found word to find a corresponding card in another stack)
END returnInField

	
HTH

Best regards from Grenoble
André

Le 26 avr. 08 à 18:25, Gregory Lypny a écrit :
> 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
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your  
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution
>




More information about the use-livecode mailing list