Reversing a list

Jan Schenkel janschenkel at yahoo.com
Thu Apr 3 01:05:47 EDT 2008


--- Sarah Reichelt <sarah.reichelt at gmail.com> wrote:
> OK people, what's the fastest way to reverse the
> order of lines in a
> list. I have a list of images gathered together by
> filtering matching
> files from a set of folders. Now I want to be able
> to reverse the
> order, but their file names are varied and so I have
> no obvious way to
> sort them.
> 
> I realise I could just use a repeat for each loop
> and put each one
> before a new list variable, but that seems rather
> clumsy, and using
> "before" slows down when I have thousands of
> records.
> 
> I'm hoping that Jacque will chime in with one of her
> custom sort ideas
> that I never can think of, but anyone is welcome to
> come up with some
> elegant solution.
> 
> Cheers,
> Sarah
> 

Hi Sarah,

Beating Jacque to it with this:

##
local sLineCount, sCurrentLine

on mouseUp
  put 0 into sCurrentLine
  put the number of lines in field 1 into sLineCount
  sort field 1 by ReverseOrder()
end mouseUp

function ReverseOrder
  add 1 to sCurrentLine
  return sLineCount - sCurrentLine
end ReverseOrder
##

How fast it is for huge datasets, I'm not sure; but it
works a treat :-)

Hope this helped,

Jan Schenkel.

Quartam Reports & PDF Library for Revolution
<http://www.quartam.com>

=====
"As we grow older, we grow both wiser and more foolish at the same time."  (La Rochefoucauld)


      ____________________________________________________________________________________
You rock. That's why Blockbuster's offering you one month of Blockbuster Total Access, No Cost.  
http://tc.deals.yahoo.com/tc/blockbuster/text5.com



More information about the use-livecode mailing list