Microsoft Visual Basic 2010 Step by Step eBook

(Tina Meador) #1

Chapter 11 Using Arrays to Manage Numeric and String Data 289


Visual Studio Help documentation. The Array class methods function much like the .NET
Framework methods you have already used in this book; that is, they are called by name
and (in this case) require a valid array name as an argument. For example, to sort an array
of temperatures (such as the Temperatures array that you created in the last exercise), you
would use the following syntax:

Array.Sort(Temperatures)

You would make such a call after the Temperatures array had been declared and filled
with data in the program. When Visual Basic executes the Array.Sort method, it creates
a temporary storage location for the array in memory and uses a sorting routine to
reorganize the array in alphanumeric order. After the sort is complete, the original array is
shuffled in ascending order, with the smallest value in array location 0 and the largest value
in the last array location. With the Temperatures example above, the sort would produce
an array of daily temperatures organized from coolest to hottest.

In the following exercise, you’ll see how the Array.Sort and Array.Reverse methods can
be used to quickly reorder a large array containing six-digit numbers randomly selected
between 0 and 1,000,000. You’ll also experiment with the ProgressBar control, which provides
useful visual feedback for the user during long sorts.

Use Array methods to sort an array of 3,000 elements


  1. On the File menu, click Open Project, and then open the Array Class Sorts project,
    located in the C:\Vb10sbs\Chap11 folder.

  2. Display the form if it is not already visible.


Your screen looks like this:
Free download pdf