How to sort on keydown

Nonsanity form at nonsanity.com
Wed Aug 3 10:00:27 EDT 2011


Since sort will re-order the items, I think what you want is "select". You
are also sorting "items" which by default means the chunks of text separated
by commas (you can change the commas to any other character by setting the
itemDelimiter), but I'm guessing you mean lines. If it actually IS items,
replace "lines" with "items" in the code below.

on keydown theKey
    show fld "MonthDropDown"
    repeat with a = 1 to the number of lines in fld "MonthDropDown"
        if char 1 of line a of fld "MonthDropDown" is theKey then
            select line a of fld "MonthDropDown"
            exit repeat
        end if
    end repeat
end keydown

Does that do what you want? You might want to limit the keys it works with
by putting an if statement around the entire guts of the handler like so:

if theKey > 64 and theKey < 91 then
  ...
end if

 ~ Chris Innanen
 ~ Nonsanity



On Wed, Aug 3, 2011 at 2:24 AM, Admin <admin at mfelkerco.com> wrote:

>
>
> Hello everyone.
>
> I wrote the following code:
>
> on keydown
>  show
> field "MonthDropDown"
>  sort items of field "MonthDropDown" by keydown
> letter
> end keydown
>
> It's wrong. I know it's wrong. How do I make it
> right? (I want the drop down list to end up on the letter of what the
> user pressed on keydown, so if they pressed 'd' or 'D' I want "December"
> to become highlighted.
>
> Thanks everyone.
>
> Mike
>
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>



More information about the Use-livecode mailing list