Simple progress counter

This functionality uses the class SysOperationProgress.

We start by declaring the necessary variables:

1
2
3
4
5
6
    // ProgressCounter
    #avifiles
    SysOperationProgress                oProgress;
    int                                  nTotal;
    #define.TITLE("Processing...")
    ;

nTotal needs to be set to a number that reflects the process that is going to take place. If we know that we will go through a loop 2000 times, then we set nTotal to the value 2000.

If we don’t know how many times we need to pick a value that works. If we think that the exact value is going to ge about 3000, then we use 3500 or higher. It’s more important that the progress bar doesn’t disapear before the process is done than it is for the progress bar to disapear exactly when the progress bar reaches 100%.

The code continues:

7
8
9
10
11
12
    // begin counter set
    nTotal = 2000;
    oProgress = SysOperationProgress::newGeneral(#aviUpdate,
                                                 #TITLE,
                                                 nTotal);
    // end counter set

In our case we set nTotal to 2000 and initiate the SysOperationProgress object as a general progress bar.

13
14
15
16
17
18
19
20
21
    while (some_condition)
    {
 
      [....]
 
      oProgress.incCount(); // Adds to the counter.
    }
 
    oProgress.hide(); // Hides counter when done.

And that is all there is to it. The tricky part is usually to predict the value of nTotal, the other code is pretty straight forward.

Last 5 posts in Development

One thought on “Simple progress counter

Leave a Reply

Your email address will not be published. Required fields are marked *