Chapter 11: Using Arrays to Manage Numeric and String Data


Chapter 11

Using Arrays to Manage Numeric and String Data

After completing this chapter, you will be able to:

  • Organize information in fixed-size and dynamic arrays.

  • Use arrays in your code to manage large amounts of data.

  • Preserve array data when you redimension arrays.

  • Use the Sort and Reverse methods in the Array class to reorder arrays.

  • Use the ProgressBar control in your programs to show how long a task is taking.

Managing information in a Microsoft Visual Basic application is an important task, and as your programs become more substantial, you'll need additional tools to store and process data. Of course, storing information in a database is the most comprehensive approach to data management in a program, and you'll start learning how to integrate Visual Basic programs with databases in Chapter 18, “Database and Web Programming.” Another classic approach to data management in programs is to store and retrieve information in auxiliary text files, as you'll see in Chapter 13, “Exploring Text Files and String Processing.”

In this chapter, you'll learn how to organize variables and other information into useful containers called arrays. You'll learn how to streamline data-management tasks with fixed-size and dynamic arrays, and how to use arrays in your code to manage large amounts of data. You'll learn how to redimension arrays and preserve the data in arrays when you decide to change an array's size. To demonstrate how large arrays can be processed, you'll use the Sort and Reverse methods in the Microsoft .NET Framework Array class to reorder an array containing random six-digit integer values. Finally, you'll learn to use the ProgressBar control to give your users an indication of how long a process (array-related or otherwise) is taking. The techniques you'll learn provide a solid introduction to the database programming techniques that you'll explore later in the book.

Upgrade Notes: Migrating Visual Basic 6 Code to Visual Basic 2005

If you're experienced with Microsoft Visual Basic 6, you'll notice some new features in Microsoft Visual Basic 2005, including the following:

  • Arrays in Visual Basic 2005 are always zero-based, as they were in Microsoft Visual Studio .NET 2002 and 2003, meaning that the lowest array element is always 0. In Visual Basic 6, programmers can use the Option Base statement, which is no longer supported, to set the base of arrays to either 0 or 1.

  • An obvious side effect of zero-bound arrays is that the LBound statement always returns a value of 0 because the lower bound for an array is always 0. (The UBound statement, however, continues to return the highest index in an array, which is the number of elements minus 1.)

  • Arrays can now be declared and assigned data by using the same program statement. For example, the syntax to declare an array named myList() and add four elements to it is

    Dim myList() as Integer = {5, 10, 15, 20}

  • The ReDim statement is still valid in Visual Basic 2005, although you can't use the ReDim statement for an initial array declaration. Visual Basic 6 and Visual Basic 2005 also have something in common in regards to ReDim: You can use this statement to change the bounds of an array, but not the number of dimensions.



Microsoft Visual Basic 2005 Step by Step
Microsoft Visual Basic 2005 Step by Step (Step by Step (Microsoft))
ISBN: B003E7EV06
EAN: N/A
Year: 2003
Pages: 168

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net