I use another For loop to print the contents of each element in the array to a Picture Box control: Private Sub cmdPrint_Click() Dim x As Integer ‘Print array elements For x = 0 To 9 Picture1.Print “Element “ & myArray(x) Next x End Sub
AM FL Y
The last two procedures handle program termination. Private Sub cmdQuit_Click() End End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) cmdQuit_Click End Sub
TE
Visual Basic Programming for the Absolute Beginner
262
Multidimensional Arrays Sometimes data cannot be accurately depicted and stored in a single dimension array. Suppose you want to store the x and y coordinates of a map or grid or the rows and columns of a record from a file. You can implement these and many other examples through the use of a two-dimensional array. Also known as multisubscripted arrays, multidimensional arrays are not limited to just two dimensions. Although it is not uncommon to have three- and even four-dimensional arrays, this section concentrates on two-dimensional arrays only. As depicted in Figure 10.5, it is easiest to visualize a two-dimensional array with rows and columns. Like their singular counterpart, multidimensional arrays share similar scope to variables, and share a common name. They have like data types, and they are referenced through element numbers (or indices). The following statement creates a two-dimensional array with four rows and four columns: Dim myArray(3, 3) As String
This gives the array a total of 16 elements. As shown in the next segment, you can also explicitly declare upper and lower bounds with two-dimensional arrays: Dim myArray(1 To 4, 1 To 4) As String
Team-Fly®