Download presentation
Presentation is loading. Please wait.
Published byHilary Doyle Modified over 9 years ago
1
Two-Dimensional Arrays
2
Two-dimensional arrays variables store the contents of tables or matrices. Example: Dim arrTable(1 to 5, 1 to 5) As Integer first row last row first column last column
3
Using For Loops to Manipulate Arrays You can efficiently process a multidimensional array by using nested For loops. The outer loop of the For loop controls the rows, and the inner loop of the For loop controls the columns
4
Private Sub FillArray(A() As Double) Dim I As Integer, J As Integer For I = 1 To 5 For J = 1 To 5 A(I, J) = I * 10 + J Next J Next I End Sub
5
Private Sub DisplayArray(A() As Double) Dim I As Integer, J As Integer For I = 1 To 5 For J = 1 To 5 picOutput.Print A(I, J); Next J picOutput.Print Next I End Sub Private Sub Command1_Click() Dim MatrixA(1 To 5, 1 To 5) As Double Call FillArray(MatrixA()) Call DisplayArray(MatrixA()) End Sub
6
Reading Table Data from a Data File into a Two-Dimensional Array Chicago Los Angles New York Philadelphia Chicago 0 2054 802 738 Los Angles 2054 0 2786 2706 New York 802 2786 0 100 Philadelphia 738 2706 100 0
7
Data File for the Table Data 0, 2054, 802, 738 2054, 0, 2786, 2706 802, 2786, 0, 100 738, 2706, 100, 0
8
Sub Procedure to Input Data from the Data File into a Two-dimensional Array Private Sub Form_Load() Dim arrTable(1 To 4, 1 To 4) As Single Dim row As Integer, col As Integer 'Fill two-dimensional array with intercity mileages 'Assume the data has been placed in the file "DISTANCE.TXT" '(First line of the file is 0, 2054, 802, 738) Open App.Path & "\DISTANCE.TXT" For Input As #1 For row = 1 To 4 For col = 1 To 4 Input #1, arrTable(row, col) Next col Next row Close #1 End Sub
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.