Home
Username:
Password:
Microsoft Visual Basic 2005 Tutorials

Arrays / Two-Dimensional Arrays




Visitors to VTC.com will be able to view all introductory videos for each training course.
Free Trial Members will gain access to first three chapters for each training course.
Full Access Members have full access to VTC.com’s entire library of video tutorials.


Learn More

Subtitles of the Movie

Many programming applications will require the use of two-dimensional Arrays rather than a one-dimensional Array. You generally need to use two Subscripts to identify any type of data that's in a table, where data is arranged in rows and columns. Many applications come to mind, such as insurance rate tables or a tax table. Provided are the two general forms of declaring a two-dimensional Array. The first example is to declare an Array with a name, just as you would with a single-dimension Array and then provide two Subscripts. The first Subscript is the upper row, upper Subscript for the row and the second one is the upper Subscript for the column. Again, just like single-dimension Arrays, this is not meaning the number of rows, the number of columns, but rather the upper Subscript. And, of course, just like with single-dimension Arrays, you also need to specify the data type, which is going to dictate what type of data can be stored in that Array. In the second example, you see again the name of the Array being specified after the word dim, but in this case you see a set of parentheses with only a comma in between. The comma inside the parentheses is necessary to specify there are two dimensions to the Array. You specify the initial values with the first dimension and the second dimension for the column. The compiler will determine the number of elements from the initial values that you supply. So by specifying the name of the Array and then leaving the parentheses open without a specific Subscript, you're allowing Visual Basic to determine the size necessary. Again, you need to specify the data type as with all cases. Here are two examples of two-dimensional Arrays. In the first example we have an Array called Last Name String with Subscripts of three comma five. The three comma five, the three represents the upper Subscript for the rows, where the five represents the upper Subscript for the columns. This Array, called Last Name String, can hold up to 24 names. Twenty-four names because there are four rows and six columns. Note that three represents rows zero through three, where in the column, the five represents columns zero through five; therefore making four rows by six columns for a total of 24 names. In the second example, we have an Array called Age Integer, which is going to create an Array which is capable of storing integer data type. This particular Array can hold up to 24, excuse me, 50 whole numbers. Fifty whole numbers because there are five rows and ten columns. Again, note that the four represents zero through four rows and the nine represents zero through nine columns, therefore making this Array a five by ten Array capable of storing up to 50 numbers. Once two-dimensional Arrays have been declared, the elements of the Array may be used in the same way as any other variable, such as with counters and accumulators and reference fields for lookups and so forth. And just the same as with single-dimension Arrays, you have to be concerned about not exceeding the bounds of the Array. That is, in the case of age integer, you could not reference a row outside of the upper Subscript of four or column outside the upper Subscript of nine.

Tutorial Information

Course: Microsoft Visual Basic 2005
Author: Arthur Lee
SKU: 33940
ISBN: 1-935320-10-6
Release Date: 2008-11-19
Duration: 7.5 hrs / 97 lessons
Work Files: Yes
Captions: Available on CD and Online University
Compatibility: Vista/XP/2000, OS X, Linux
QuickTime 7, Flash 8

VTC Sign up & Benefits

  • Unlimited Access
  • 98,729 Video Tutorials (23,265 free)
  • Video Available as Flash or QuickTime
  • Over 1026 Courses
  • $30 for One Month Access
  • Multi-User Discounts Available