i am just wondering how vb sets up an array, if i want to set up and array like the following, with 2 rows and 4 columns
1 1 1 1
1 1 1 1
do i set it up as Dim Matrix(1 To 2, 1 To 4) As Double
or as Dim Matrix(1 To 4, 1 To 2) As Double
Printable View
i am just wondering how vb sets up an array, if i want to set up and array like the following, with 2 rows and 4 columns
1 1 1 1
1 1 1 1
do i set it up as Dim Matrix(1 To 2, 1 To 4) As Double
or as Dim Matrix(1 To 4, 1 To 2) As Double
Dim Matrix(1 To 2, 1 To 4) As Double
the first dimension, 1 to 2 will give you:
1
2
The second, 1 4, will give the first dimension, dimension (I wish I knew technical terms) so it'll become
1 - 1 2 3 4
2 - 1 2 3 4
Either depending on how you use, but if you want in the x,y co-ordinate system, use:
Dim Matrix(1 To 2, 1 To 4) As Double
Quote:
MSDN
Multidimensional Arrays
Sometimes you need to keep track of related information in an array. For example, to keep track of each pixel on your computer screen, you need to refer to its X and Y coordinates. This can be done using a multidimensional array to store the values.
With Visual Basic, you can declare arrays of multiple dimensions. For example, the following statement declares a two-dimensional 10-by-10 array within a procedure:
Static MatrixA(9, 9) As Double
Either or both dimensions can be declared with explicit lower bounds:
Static MatrixA(1 To 10, 1 To 10) As Double
You can extend this to more than two dimensions. For example:
Dim MultiD(3, 1 To 10, 1 To 15)
This declaration creates an array that has three dimensions with sizes 4 by 10 by 15. The total number of elements is the product of these three dimensions, or 600.
Note When you start adding dimensions to an array, the total storage needed by the array increases dramatically, so use multidimensional arrays with care. Be especially careful with Variant arrays, because they are larger than other data types.
Both of them will work.Quote:
Originally posted by james007lamb
do i set it up as Dim Matrix(1 To 2, 1 To 4) As Double
or as Dim Matrix(1 To 4, 1 To 2) As Double
Dim Matrix(1 To 2, 1 To 4) will produce:
1 1
1 1
1 1
1 1
Dim Matrix(1 To 4, 1 To 2) will produce
1 1 1 1
1 1 1 1