Arrays, multi-dimensional

  • Thread starter Thread starter Jim
  • Start date Start date
J

Jim

I am looking to carry a grid of various types of
information in a single variable. The grid is 3 rows by
six columns. I seem to have "dim"d the array OK (at least
VB doesn't bark at me)...

Dim matls(1 To 3, 1 To 6) As Variant

....but I cannot seem to populate its individual rows with
the six pieces of data that need to go there. Help in
Access seems limited to one-row arrays. Anyplace I can go
to see an example?

Thanks!
 
Example...

Dim arrMatls (1 to 3, 1 to 6) As Variant
Dim i as Integer
Dim j as Integer

For i = 1 to 3
For j = 1 to 6
arrMatls(i,j) = i * j
Next
Next

For i = 1 to 3
For j = 1 to 6
Debug.Print arrMatls(i,j)
Next
Next
 
Jim said:
I am looking to carry a grid of various types of
information in a single variable. The grid is 3 rows by
six columns. I seem to have "dim"d the array OK (at least
VB doesn't bark at me)...

Dim matls(1 To 3, 1 To 6) As Variant

...but I cannot seem to populate its individual rows with
the six pieces of data that need to go there. Help in
Access seems limited to one-row arrays. Anyplace I can go
to see an example?

'populate first row
matls(1,1) = data1
. . .
matls(1,6) = data6
'populate second row
matls(2,1) = dataA
. . .

Seems too simple, I must not grasp the issue you're asking
about??
 
Actually, it is simple. I was trying to populate whole
rows at a time using the "array()" function - clearly
overcomplicating things. Thanks for your help!

- Jim -
 
-----Original Message-----
I am looking to carry a grid of various types of
information in a single variable. The grid is 3 rows by
six columns. I seem to have "dim"d the array OK (at least
VB doesn't bark at me)...

Dim matls(1 To 3, 1 To 6) As Variant

....but I cannot seem to populate its individual rows with
the six pieces of data that need to go there. Help in
Access seems limited to one-row arrays. Anyplace I can go
to see an example?

Thanks!
.
Hi Jim,
what I do in this circumstance is use a Type for each
elment of a row and then create an array of that type.

general declarations
private Type myType
typeOne as string
typeTwo as string
...
end type


private sub myProc()
Dim matls(1 To 3) As myType
with matls(1)
..typeOne="things"
..typeTwo="more things"
....
end with

in addition to making it easier to work with multi-
dimension arrays it is also easier to read code.

Luck
Jonathan
 
Actually, it is simple. I was trying to populate whole
rows at a time using the "array()" function - clearly
overcomplicating things. Thanks for your help!

The array() function always returns a Variant, and it can only be assigned
to a variant sic:

Public Sub MakeRectArray()

Dim vMyArray As Variant

' one-dimensional
vMyArray = Array(1, 2, 3, 4, 5, 6)

' 2-D and upwards can be nested
vMyArray = Array(Array(1, 2, 3, 4, 5, 6), _
Array(11, 12, 13, 14, 15, 16), _
Array(21, 22, 23, 24, 25, 26))

' I'm afraid that this doesn't work either!
' Dim a_dwRealThing(0 To 2, 0 To 5) As Long
' a_dwRealThing = vMyArray

End Sub


B Wishes


Tim F
 
Back
Top