Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /var/sites/d/davestewart.io/public_html/index.php:44) in /var/sites/d/davestewart.io/public_html/wordpress/wp-content/themes/hoarder/framework/zilla-admin-init.php on line 16

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /var/sites/d/davestewart.io/public_html/index.php:44) in /var/sites/d/davestewart.io/public_html/wordpress/wp-content/themes/hoarder/framework/zilla-admin-init.php on line 16
Progress Bar Updater | Dave Stewart IO

Progress Bar Updater

Updating a progress bar is fairly simple in conceptual terms, but it always takes a slightly different bit of code to do it right:

  • What if the sequence is backwards?
  • What if you're incrementing in units of 2, or 3, or 10?
  • How big is the progress jump?

It makes sense to abstract the process and stick it in a struct. The progressBarUpdater does just that, and really is as simple as:

  1. Create a struct instance
  2. Initialize it with a reference to a progress bar, and the known start and end values of the calculation
  3. Call update() for each loop iteration.

In code, starting with a 2-line initialization, it looks like this:

pbu = progressBarUpdater()
pbu.init pb1 startValue endValue

And to update the progress bar, this is the only command you need to place in the loop:


The pbUpdater struct already knows everything it needs to know, so it's just one call.


Download progressBarUpdater.ms.

Leave a Comment