G'day "VBA Coder" <
[email protected]_SPAM.>,
FWIW, WordBasic.Sort MyArray is MUCH faster
Additionally, there are 3 different sort techniques for 3 different
situations.
Bubble sort: Small lists (<100 items, ie all our userform
requirements) and almost-sorted lists.
Shell sort: 100-1000 items, maybe more dep on instancing.
Quick sort/Partition Sort: 1000 items plus
To round up the whole subject, there is also the batch sort. You use
this for extremely large databases where you cannot load the entire
dataset into memory. As it is the least documented and most useful to
us (the other 3 are better off being replaced with
wordbasic.sortarray) I include some pseudo-code for the reader's
erudition.
open outputfile
open inputfile
'Precursor
'A simple way to make runs out of existing almost sorted data
While not eof(inputfile)
read next value
if value > oldvalue then
write to outputfile
else
close outputfile
open outputfilename+1
end if
wend
'converge runs
lastoutputfilename =outputfile
while outputfilename < lastoutputfilename
open oldoutputfilename for read
open oldoutputfilename +1 for read
open newoutputfilename for append (use the same naming convention,
num sequencing as last output file series, we just continue the
series)
read var1 from oldoutputfilename
read var2 from oldoutputfilename+1
if var1<var2
write var1
read next var1
if eof oldoutputfilename then write remainder of other file to
output
else
write var 2
read next var2
if eof oldoutputfilename+1 then write remainder of other file to
output
end if
close & del both read files
lastoutputfilename=newoutputfilename
inc oldoutputfile +2
wend
rename last output file to desired name, it contains the sorted
output.
Depending on the sort characteristics of the data itself and memory
available, you can also load in buffers worth of data and sort that
into a run for dumping to an outputfile as the precursor processing.
This is quite common in batch processing as you redo the process over
numerous data sources to obtain your input figures, and generally you
sort from each data source before output. Your routine then runs the
converge, etc.
ps: change
If .List(i) < .List(j) Then
to a > to get descending
VBA Coder said:
Helmut,
You code was a winner, but now the client wants the ability to sort
Descending. I have been playing around with your code, but can't quite get
it to sort Descending.
Can you help me out?
Thanks.
Steve Hudson
Word Heretic, Sydney, Australia
Tricky stuff with Word or words for you.
wordheretic.com
If my answers r 2 terse, ask again or hassle an MVP,
at least they get recognition for it then.
Lengthy replies offlist require payment.