Looking for inspiration
Ken Ray
kray at sonsothunder.com
Wed Dec 19 12:54:53 EST 2007
On Wed, 19 Dec 2007 16:29:48 -0000, Beynon, Rob wrote:
> I'm writing tools that bash their way through thousands of lines of
> input text, and do some processing.
>
> I'd like to have a progress indicator displayed (and indeed, live the
> tm dials, in particular, that I just got for Xmas!).
>
>
>
> But, how does one write a routine to indicate progress without
> imposing a penalty at each iteration?
Richard Gaskin told me of a great way to do that, and the only
"penalty" is knowing how many lines you're going to be dealing with
*before* you get started. But assuming you know that, here's what you
do:
1) Create a progress bar with an endValue of 100 and startValue of 0.
2) Take the total number of lines that you're processing and divide it
by 100 (rounding of course) to determine how many lines you need to
process before you increment the progress bar by one (I call this the
"progress chunk").
3) During processing, increment a counter variable for each line, and
if "<counter> mod <progressChunk> = 0" then increment the progress bar.
Something like:
on ProcessData pData
put the number of lines of pData into tMaxLines
put round(tMaxLines/100) into tProgChunk
put 0 into tCounter
put 0 into tThumbPos
repeat for each line tLine in pData
add 1 to tCounter
if tCounter mod tProgChunk = 0 then
add 1 to tThumbPos
set the thumbPos of sb "Progress" to tThumbPos
end if
-- process your data here
end repeat
end ProcessData
Obviously you can "scale" this if the granularity you'd like to show is
less than 1% of the overall total at a time, but I haven't really found
a need for that...
Ken Ray
Sons of Thunder Software, Inc.
Email: kray at sonsothunder.com
Web Site: http://www.sonsothunder.com/
More information about the use-livecode
mailing list