# Creating a Progress Bar

**URL:** <https://www.ruby-forum.com/t/creating-a-progress-bar/156964>\
**Category:** wxRuby\
**Created:** [January 5, 2009, 9:46pm UTC](https://www.ruby-forum.com/t/creating-a-progress-bar/156964 "2009-01-05T21:46:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sweatje](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ad7895/32.png) [@sweatje](https://www.ruby-forum.com/u/sweatje)\
**Post date:** [January 5, 2009, 9:46pm UTC](https://www.ruby-forum.com/t/creating-a-progress-bar/156964/1 "2009-01-05T21:46:17Z")

</div>

All,

I am attempting to add a progress bar to my application. What is  
prompting the progress bar to be displayed is the pressing of a button.  
This button performs an action, and for the sake of an example, lets say  
that it is printing one million words to the screen. While these words  
are printing to the screen, I want a progress bar to be running. I want  
the bar to fill completely, then go blank, and fill completely over and  
over again until all of the words are printed to the screen. Once all  
of the words are printed, I want the progress bar to stop its routine. I  
have the progress bar up and running, but my problem is that I am using  
a while loop to continuously fill the bar, so in turn it is running  
infinitely, and the code that comes after it, the words printing, is  
never being executed. I can elaborate if necessary. Thanks in advance  
for all of your assistance.

- Shelton

---

<div class="post-metadata">

**Author:** ![sweatje](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ad7895/32.png) [@sweatje](https://www.ruby-forum.com/u/sweatje)\
**Post date:** [January 5, 2009, 11:34pm UTC](https://www.ruby-forum.com/t/creating-a-progress-bar/156964/2 "2009-01-05T23:34:14Z")

</div>

Jason S. wrote:

I guess you mean ProgressDialog or Gauge. They will both do roughly the  
same thing, but the former will display it in a standalone dialog.

> I am attempting to add a progress bar to my application. What is  
> prompting the progress bar to be displayed is the pressing of a  
> button. This button performs an action, and for the sake of an  
> example, lets say that it is printing one million words to the  
> screen. While these words are printing to the screen, I want a  
> progress bar to be running. I want the bar to fill completely, then  
> go blank, and fill completely over and over again until all of the  
> words are printed to the screen. Once all of the words are printed, I  
> want the progress bar to stop its routine.

Use the ‘maximum’ argument of ProgressDialog to set how many steps there  
are to progress through. In your case, it might be the number of words.  
Use the #update method to set how many steps have been completed. The  
dialog is automatically dismissed when the full number of steps is  
finished, or call #close to finish it early.

It works the same with Gauge, except you use #value= to set how many  
steps have been done.

> I have the progress bar up and running, but my problem is that I am  
> using a while loop to continuously fill the bar, so in turn it is  
> running infinitely, and the code that comes after it, the words  
> printing, is never being executed.

Well, don’t use an infinite while loop… either call break somewhere in  
the loop to exit it, or use an ‘each’ loop over the right number of  
items.

If that’s not it, perhaps describe your question more clearly, and if  
possible show a little sample of code that you’re working on.

a

---

<div class="post-metadata">

**Author:** ![sweatje](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ad7895/32.png) [@sweatje](https://www.ruby-forum.com/u/sweatje)\
**Post date:** [January 15, 2009, 2:50pm UTC](https://www.ruby-forum.com/t/creating-a-progress-bar/156964/3 "2009-01-15T14:50:25Z")

</div>

solved a similar problem here…

[http://www.ruby-forum.com/topic/175626](http://www.ruby-forum.com/topic/175626)

Hope it helps,

John.
