Question

It seems trivial, but I cant find a clean algorithm to this.

I can calculate my total rows to 2186.

Then I thought I do a 2186 / 100 = 21 (which would be my modNr) Then I thought I would increment the currentRowNr++ inside Backgroundworker.reportprocess() And do a if(currentRowNr % modNr == 0) increment progressbar.

The progress bar now seems to behave correctly however, it doesnt stop at 100. I get an expection that the number went over maximal of 100. My algorithm seems wrong.

There must be a clean solution for this and I am just making it overcomplicated. Anyone good in math? ;-)

Thank you

Was it helpful?

Solution

Set the Maximum property of the progessbar to 2186 and Minimum property to 0. Now every time you got past a single item in your processing you increase the value of the progressbar by 1. Removes the need for an algorithm at all since the progessbar will take care of that for you.

OTHER TIPS

It is clear : 2121 = 101 * 21, and 2142, 2163, 2184 will also be > 100

It is a simple rounding problem.
If you use 2186 / 100 + 1 = 22 as modNr you will end up with 99 on the last hit. For ultra precision, follow Qua's answer and reconfigure the progressbar.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top