Microsoft Visual Basic 2010 Step by Step eBook

(Tina Meador) #1

Chapter 11 Using Arrays to Manage Numeric and String Data 293


ByVal e As System.EventArgs) Handles Button2.Click
Dim i As Integer
TextBox1.Text = ""
Array.Sort(RandArray)
For i = 0 To UBound(RandArray)
TextBox1.Text = TextBox1.Text & RandArray(i) & vbCrLf
ProgressBar1.Value = i 'move progress bar
Next i
End Sub
This event procedure clears the text box object when the user clicks the Sort Array
button, and then sorts the array by using the Array.Sort method described earlier. The
sorting process is very quick. Again, the only slowdown is rebuilding the text box object
one line at a time in the For... Next loop, a process that is reported by the ProgressBar1
object and its Value property. See how simple it is to use the Array.Sort method?


  1. Click the Reverse button.


The program uses the Array.Reverse method to manipulate RandArray, reordering the
array in backward or reverse order; that is, the first element becomes last and the last
element becomes first.

Note This method does not always produce a sorted list; the array elements are in
descending order only because RandArray had been sorted previously in ascending order by
the Array.Sort method. (To examine the list more closely, use the scroll bars or the
arrow keys .)

Your screen looks like this:
Free download pdf