Microsoft Visual Basic 2010 Step by Step eBook

(Tina Meador) #1

Chapter 11 Using Arrays to Manage Numeric and String Data 291


For a progress bar to display an accurate indication of how long a computing task will
take to complete, you need to set relative measurements for the beginning and the end
of the bar. This is accomplished with the Minimum and Maximum properties, which are
set to match the first and the last elements in the array that we are building. As I have
noted, the first array element is always zero but the last array element depends on the
size of the array, so I have used the UBound function to return that number and set the
progress bar Maximum property accordingly. The array that we are manipulating in this
exercise is RandArray, a Long integer array declared initially to hold 500 elements
(0 to 499).


  1. Click the Start Debugging button to run the program.


The program runs, and the Array Class Sorts form opens on the screen. In its
Form1_Load event procedure, the program declared an array named RandArray
and dimensioned it with 500 elements. A progress bar object was calibrated to track
a calculation of 500 units (the array size), and the number 500 appears to the right of
the progress bar (the work of a label object and the UBound function).


  1. Click the Fill Array button.


The program loads RandArray with 500 random numbers (derived by the Rnd function),
and displays the numbers in the text box. As the program processes the array and fills
the text box object with data, the progress bar slowly fills with the color green. Your
screen looks like this when the process is finished:

The code that produced this result is the Button1_Click event procedure, which contains
the following program statements:

'Fill the array with random numbers and display in text box
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Free download pdf