CProgressCtrl Bar Not Displaying Accurate Progression

mr_stevie
mr_stevie used Ask the Experts™
on
Hello EE,

I am making a program that reads a file, does its calculations, and outputs the calculations.

The filenames are stored in a series of std::vectors and the program goes through each one until it is finished.

While this is happening, a dialog with a CProgressCtrl variable is displayed to indicate the progress of the process, calling StepIt() every time a file is finished outputting the file.

However, it does not depict an accurate progression as it continually shows a complete bar and then an empty bar again which continues to progress to a complete bar then empties again.

I am initialising the range like this:

int max = vector1.size() + vector2.size() + vector3.size();
ProgressBar.SetRange( 0 , max );
ProgressBar.SetStep(1);

If someone can tell me what I am doing wrong, it would be greatly appreciated.

Thanks.


Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
What is the value of max?

Author

Commented:
Max is an integer representing the addition of the size of all the vectors defined.

Commented:
Yes, I realize that, but what is the actual value? Have it print it in a message box or to a debug window. Could it be possible that the vectors are all just size 1?
Should you be charging more for IT Services?

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
I should say that it doesn't go from 0% to 100%. It increments like 5% every time and when it reaches 100%, it goes back to 0%.

The size of the vectors are dynamic. It can range from 100 to 1000 entries.

Commented:
If it is incrementing by 5%, perhaps max is only 20? Perhaps you are calling ProgressBar.StepIt() multiple times per operation? It is hard to give you a good answer without seeing how these commands relate to the rest of your code.

One of my guesses is all the vectors initialized before int max = vector1.size() + vector2.size() + vector3.size();?

If you run int max = vector1.size() + vector2.size() + vector3.size(); then add to the vectors, of course your max would be off. This is why I am recommending you debug the actual value of max.
Freelance programmer / Consultant
Commented:
Instead of using StepIt try using SetPos instead.

eg.
ctl.SetRange(0, 1000);

for(int i = 0; i <= 1000; i++)
{
.....
  ctl.SetPos(i);
}  

Author

Commented:
It seems that it will only work if I call SetRange() every time before I increment the progress every time I call it.

Though this is not ideal, it seems to work as intended now...
AndyAinscowFreelance programmer / Consultant

Commented:
No - SetRange should only need to be called once.  If it does behave as you say then it seems like you have another problem elsewhere.
Please post the code you have for the loop (where you use SetPos)

Commented:
Mr. Stevie - is your vectors growing and shrinking during the loop? I have a feeling that is your issue.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial