|
-
May 8th, 2002, 05:29 PM
#1
Easy - array dimensions
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
-
May 8th, 2002, 05:31 PM
#2
Stuck in the 80s
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
-
May 8th, 2002, 05:32 PM
#3
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
Need to re-register ASP.NET?
C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i
(Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)
-
May 8th, 2002, 05:34 PM
#4
-= B u g S l a y e r =-
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.
-
May 8th, 2002, 05:40 PM
#5
Re: Easy - array dimensions
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
Both of them will work.
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|