PC Review


Reply
Thread Tools Rate Thread

Arrays, multi-dimensional

 
 
Jim
Guest
Posts: n/a
 
      5th Jul 2004
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!
 
Reply With Quote
 
 
 
 
Paul Overway
Guest
Posts: n/a
 
      5th Jul 2004
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


--
Paul Overway
Logico Solutions, LLC
www.logico-solutions.com


"Jim" <(E-Mail Removed)> wrote in message
news:2758c01c462d2$d125b4e0$(E-Mail Removed)...
> 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!



 
Reply With Quote
 
Marshall Barton
Guest
Posts: n/a
 
      5th Jul 2004
Jim wrote:

>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??

--
Marsh
MVP [MS Access]
 
Reply With Quote
 
Jim
Guest
Posts: n/a
 
      6th Jul 2004
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-----
>Jim wrote:
>
>>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??
>
>--
>Marsh
>MVP [MS Access]
>.
>

 
Reply With Quote
 
Jonathan Parminter
Guest
Posts: n/a
 
      6th Jul 2004

>-----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

 
Reply With Quote
 
Tim Ferguson
Guest
Posts: n/a
 
      7th Jul 2004
"Jim" <(E-Mail Removed)> wrote in
news:26cfb01c462f5$c94cce20$(E-Mail Removed):

>
> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Multi-dimensional arrays Amien Crombie Microsoft C# .NET 2 5th Jun 2009 02:02 PM
More Multi-Dimensional Arrays =?Utf-8?B?Q2xheW1hbg==?= Microsoft Excel Programming 1 31st Jul 2007 05:18 PM
More Multi-Dimensional Arrays =?Utf-8?B?Q2xheW1hbg==?= Microsoft Excel Programming 0 31st Jul 2007 05:10 PM
Multi-dimensional arrays gti_jobert Microsoft Excel Programming 6 6th Feb 2006 04:45 AM
Multi Dimensional Arrays DazedAndConfused Microsoft VB .NET 4 26th Jul 2005 11:08 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:57 AM.