Visual Basic 2008 Programming: Business Applications with a Design Perspective
Chapter 1 Chapter 2 Chapter 3 Chapter 4 Chapter 5 Chapter 6 Chapter 7 Chapter 8 Chapter 9
Chapter 10 Chapter 11 Chapter 12 Chapter 13 Chapter 14 Appendix A Appendix B Appendix C Home
Loading
Last change: February 13 2016 18:48:19.

 Chapter in PDF

Table of Contents

Chapter 8: Arrays and Their Uses
Last change: February 13 2016 18:48:01.
<<PreviousNext>>

8.4   Two-Dimensional Arrays

As stated at the beginning of this chapter, array variables can have more than one dimension. Consider the case of two-dimensional variables. The syntax to declare a two-dimensional variable is as follows:

Dim Name(UB1, UB2) As Type

where Name = any legitimate variable name,
UBn = an integer representing the upper bound for the nth subscript,and
Type = any valid data type.

As you can see, the only difference between a two-dimensional array and one-dimensional array is the number of subscript(s). When a variable has more than one subscript, use commas to separate the subscripts. The following are examples of valid declarations of two-dimensional arrays:

Dim A(9, 9) As Integer Dim Weights(Row, Col) As String

The first line declares a 10 x 10 Integer array, A, depicted as follows:

A(0, 0)     A(0, 1)     A(0, 2)     ...   A(0, 9) A(1, 0)     .     .     .                 A(1, 9) .     .     .     .     . A(9, 0)                                   A(9, 9)

The second line declares a Weights String table whose size depends on the values of the variables, Row and Col. These two variables should exist and have been assigned proper values before the Dim statement is executed.

Two-dimensional arrays can be used to handle various kinds of two-dimensional data. The following discussion explains how they can be used to represent tables, matrices, and even game boards.

Last change: February 13 2016 18:48:05.
  1. Simplified Selection
  2. Table Look Up
  3. Tracking Random Occurrences
  4. Simulation
  5. Random Sampling Without Replacement
  6. Sorting and Searching
  • 8.3 Control Arrays
  • 8.4 Two-Dimensional Arrays
    1. Tables
    2. Matrices
    3. Game Boards
    4. <<PreviousNext>>