Here's a routine I threw together for you. Rather than a property
list, it uses a linear list of numbers (they don't even need to be
sorted). It would probably be more useful for you to set up the
"lIntegersToCheckAgainst" below outside this routine and pass it in
instead.
on Find3Closest usersInteger
lIntegersToCheckAgainst = [1,3,5,7,9,11,13,15,17,45,78,23,85,94,213,1234]
lClosest = [0, 0, 0] -- this will be the final answer
-- start at max dist, each will be replaced if a closer answer is found
lDistances = [the maxInteger, the maxInteger, the maxInteger]
repeat with thisCheckInteger in lIntegersToCheckAgainst
thisDistance = abs(thisCheckInteger - usersInteger) -- find this distance
repeat with i = 1 to 3
if thisDistance <= lDistances[i] then
-- delete the last item and add this one here
deleteAt(lDistances, 3)
deleteAt(lClosest, 3)
addAt(lDistances, i, thisDistance)
addAt(lClosest, i, thisCheckInteger)
exit Repeat
end if
end repeat
end repeat
sort lClosest -- give the answer a nice order
return lClosest
end
Does this do what you want?
Irv
At 11:16 PM +0000 12/12/01, nik crosina wrote:
>Dear List,
>
>I have to create a search facility that finds the three closest
>values to a integer input by the user. The values searched reside in
>a property list. So it is not the more usual text searching for
>which I have already found numerous references in the archive.
>
>Has anyone done somthing like this before, or has any ideas,
>thoughts, comments?
>
>Very much appreciated and many thanks
>
>Nik
>C.
>
>[To remove yourself from this list, or to change to digest mode, go to
>http://www.penworks.com/LUJ/lingo-l.cgi To post messages to the list,
>email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED])
>Lingo-L is for learning and helping with programming Lingo. Thanks!]
--
Lingo / Director / Shockwave development for all occasions.
(Home-made Lingo cooked up fresh every day just for you.)
[To remove yourself from this list, or to change to digest mode, go to
http://www.penworks.com/LUJ/lingo-l.cgi To post messages to the list,
email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED])
Lingo-L is for learning and helping with programming Lingo. Thanks!]