Hello Mr Weber, and thanks for replying. Certainly, it is difficult to
calculate because at the start we do not know how much work is required to
sort the data, but then I found a quicksort sub (in VBS) which includes
progress percentage (written by Loren Eslinger at the Win32Scripting website):
http://cwashington.netreach.net/depo/view.asp?Index=1016&ScriptType=vbscript
I have figured out roughly how it does it, but my attempts to extract the
progress-related code and apply it to my software have failed.
Can you see how it works?
Hi Stephen,
How it works is "approximately". <g>
One of the major concepts in the mathematical study of sorting is the
"order" of a sort method, which is the number of operations (typically, the
number of swaps of position) used for a completed sort as a function of the
number of items to be sorted.
The actual order for a particular input data set depends both on the method
used and the amount of disorder present in the data. The quicksort method
performs best with very random data, and quite poorly with data that is
already almost sorted (or almost in reverse order).
On average, though, the order of the sort is a logarithmic function.
Eslinger expressed it in his code as the variable lngBigO:
'In a QuickSort BigO=(n*Log(n))
'In pratical testing BigO appears to be BigO=((n*Log(n))/3) + (n/3)
If IsEmpty(lngBigO) Then
lngEls = hiBound - loBound + 1
lngBigO = Round((lngEls * Log(lngEls))/3) + (lngEls/3)
blnFirst = True
End If 'IsEmpty(lngBigO)
That is, lngBigO is the *expected* number of swaps for the given data. The
actual number required may be more or less than that, so the progress report
may not behave smoothly near the end of the run.
The other part of the progress mechanism is to count the number of swaps as
they happen, for which Eslinger uses the variable lngProgress. This is the
code at the beginning of the loop that does the swaps:
Do
If blnProgress Then
lngProgress = lngProgress + 1
End If 'blnProgress
Then the approximate percentage progress is reported just before the
recursive calls by
If Round((lngProgress/lngBigO),2) * 100 > lngPrevious Then
Wscript.Echo Cstr(Round((lngProgress/lngBigO),2) * 100) & "%"
lngPrevious = Round((lngProgress/lngBigO),2) * 100
End If 'Round((lngProgress/lngBigO),2) * 100 > intPrevious
Depending on how accurate the estimate of lngBigO is, the sort may finish
before the progress percentage reaches 100%, or it may go on to 200% or
more.

Signature
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
> Hello Mr Weber, and thanks for replying. Certainly, it is difficult to
> calculate because at the start we do not know how much work is
> required to sort the data, but then I found a quicksort sub (in VBS)
> which includes progress percentage (written by Loren Eslinger at the
> Win32Scripting website):
http://cwashington.netreach.net/depo/view.asp?Index=1016&ScriptType=vbscript
> I have figured out roughly how it does it, but my attempts to extract
> the progress-related code and apply it to my software have failed.
[quoted text clipped - 7 lines]
>> Neither are mine, by no means. But as far as I understand this,
>> you can't know how many steps sorting will need, before you did it.
http://www.iti.fh-flensburg.de/lang/algorithmen/sortieren/quick/quicken.htm
>> Greetings from Bavaria, Germany
>>
>> Helmut Weber
>>
>> Win XP, Office 2003
>> "red.sys" & Chr$(64) & "t-online.de"
stephenc - 28 Jun 2005 12:07 GMT
Thanks very much Jay for looking into how the code works, and for explaining
it so completely. I've learned a good deal from it.
I had guessed that Eslinger was doing some kind of estimation, but could not
see exactly how she was doing it, or how accurate/inaccurate it was. I'm now
having a go at including the calculations in my code.
(Sorry I did not reply sooner but I was on vacation for a week.)
Thanks again. :-)
Stephenc
> Hi Stephen,
>
[quoted text clipped - 74 lines]
> >> Win XP, Office 2003
> >> "red.sys" & Chr$(64) & "t-online.de"
> Hello Mr Weber, and thanks for replying. Certainly, it is difficult to
> calculate because at the start we do not know how much work is required to
> sort the data, but then I found a quicksort sub (in VBS) which includes
> progress percentage (written by Loren Eslinger at the Win32Scripting website):
In general, for quicksort, you cannot rely on a progress meter.
quicksort depends very much on the type of data, the range of values, the
particular quicksort algorithm, AND the method of implementing the
algorithm.
See http://www.standards.com/index.html?Sorting
stephenc - 01 Jul 2005 15:38 GMT
Oops! forgot my manners. Thanks for helping out, Howard. Much appreciated.
I have now got a percentage calc/estimate working.
Stephenc
> > Hello Mr Weber, and thanks for replying. Certainly, it is difficult to
> > calculate because at the start we do not know how much work is required to
[quoted text clipped - 8 lines]
>
> See http://www.standards.com/index.html?Sorting