Re: Choose from list
Re: Choose from list
- Subject: Re: Choose from list
- From: Arthur J Knapp <email@hidden>
- Date: Wed, 08 May 2002 10:25:43 -0400
>
Date: Tue, 07 May 2002 20:09:14 -0400
>
Subject: Re: Choose from list
>
From: Stephen Swift <email@hidden>
>
At 5/6/02 1:27 PM, Arthur J Knapp (email@hidden) Wrote:
>
> on StrIndex(i)
>
> set s to return
>
> repeat i times
>
> set s to s & space
>
> end repeat
>
> end StrIndex
>
>
>
> set a to {"Item 1" & StrIndex(1), "Item 2" & StrIndex(2),
>
> "Item 3" & StrIndex(3), "Item 4" & StrIndex(4)}
>
Cool. However, doesn't this require the script to calculate every one of
>
the handlers? Would I see a drop in speed when I had a list of 50 or 100?
Sorry, I should have pointed out that I use this particular method within
compile-time properties:
property StaticUnchangingList : ,
{ "Item 1" & return & " " } & ,
{ "Item 2" & return & " " } & ,
{ "Item 3" & return & " " } & ,
etc...
We typically show choose-from-list dialogs with values known at the time
of compilation. In more dynamic situations, we either have to search or
we have to built the data incrementally:
set a to {}
set s to space
repeat (whatever)
set a's end to (whatever) & return & s
set s to s & space
>
> choose from list a
>
>
>
> set s to item 1 of result --> cfl returns a list
>
>
>
> set x to length of paragraph -1 of s --> offset of selected item in a
>
> (* Binary "Contains" Search:
>
> *)
>
> on BCSearch(a, v)
>
> tell a to if it contains {v} then
>
> set l to 1
>
> set r to length
>
> repeat until item l = v
>
> set m to (l + r) div 2
>
> if items l thru m contains {v} then
>
> set r to m
>
> else
>
> set l to m + 1
>
> end if
>
> end repeat
>
> return l
>
> end if
>
> return 0
>
> end BCSearch
>
This is awesome! This is my new favorite way to generate item #'s! Thanks.
>
Are there any advantages/disadvantages in using this method (BCSearch) vs.
>
StrIndex? With a little tweaking, they do basically the same thing. Is it
>
just a matter of preference?
Again, with a little extra work at compile-time, one can speed up runtime
execution. Searching can be a bit of a bother when a simplier alternative
is available through structuring one's data.
{ Arthur J. Knapp, of <
http://www.STELLARViSIONs.com>
<
mailto:email@hidden>
try
<
http://homepage.mac.com/kshook/applescript.html>
on error number -128
end try
}
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.