37
Visual Basic 6 Black Book:Toolbars, Status Bars, Progress Bars, And Coolbars
Figure 15.24 Using a simple status bar.
TIP: One reason programmers used to use simple status bars was to show the progress of an
operation by displaying a succession of dots (or other text) in the status bar’s single long panel.
However, you can use the progress bar control for that these days—see the next topic in this
chapter.
Adding A Progress Bar To A Form
The Testing Department is calling again. Why does downloading the 200MB data file your
program requires take so long? Well, you explain, the Internet is like that. They ask, but can’t
you at least show the user what progress the downloading operation is making? You take a look
at the Progress Bar Control tool in the Visual Basic toolbox. Sure, you say, no problem.
You can use progress bar controls to show the progress of a time-consuming operation. These
controls display a colored band that can grow (or shrink) as time goes on. To add a progress bar
to a form, follow these steps:
1. Select the Project|Components menu item.
2. Click the Controls tab in the Components dialog box.
3. Select the Microsoft Windows Common Controls item, and click on OK to close the
Components dialog box. This adds the Progress Bar Control tool to the Visual Basic
toolbox, as shown in Figure 15.3.
4. To place a progress bar in your form, just add it as you would any control, using the
Progress Bar Control tool.
5. Set the progress bar’s Min (default is 0) and Max (default is 100) properties as desired
to match the range of the operation you’re reporting on.
Now you’ve got a new progress bar in your form—but how do you use it? See the next topic.
Using A Progress Bar
Now that you’ve added a progress bar to your program and set its Min and Max properties, how
do you actually use it to display data? You use a progress bar’s Value property (available only at
runtime) to specify how much of the progress bar is visible. As you might expect, setting Value
to Min means none of the progress bar is visible, and setting it to Max means all of it is.
Let’s see an example. In this case, we’ll let the user click a button to display a progress bar
whose bar lengthens from Min to Max in 10 seconds. Add a progress bar, command button, and
a timer control to a form now. Set the timer’s Interval property to 1000 (in other words, 1000
milliseconds, or 1 second). We’ll leave the progress bar’s Min property at 0 and its Max
property at 100, the defaults.
When the form loads, we disable the timer and set the progress bar’s Value to 0:
Private Sub Form_Load()
file:///E|/Program%20Files/KaZaA/My%20Shared%...Basic%20-%20%20Black%20Book/ch15/489-493.html (3 of 4) [7/31/2001 9:01:25 AM]