Home All Groups Group Topic Archive Search About

2 dimensional array question

Author
20 Nov 2006 11:00 PM
fniles
I need to store information in a 2 dimensional array. I understand ArrayList
only works for a single dimensional array, is that correct ?
So, I use the 2 dimensional array like in VB6. I pass the array into a
subroutine, and inside it I "Redim Preserve" the array to increase the
number of item in the array. I got the error "Redim statement requires an
array", but arr is an array. HOw can I fix this problem ? Or, how can I do
ArrayList for 2 dimensional array ?
THank you very much.

Private arr(COM_MAX, 0) As String
LoadArr(arr)

Sub LoadArr(ByRef arr As Array)
lNumComm = 0
For x = 1 to 1000
ReDim Preserve arr(COM_MAX, lNumComm)--->Redim statement requires an array
Show quoteHide quote
:
next

Author
20 Nov 2006 11:36 PM
Michael C
Show quote Hide quote
"fniles" <fni***@pfmail.com> wrote in message
news:OlkQffPDHHA.652@TK2MSFTNGP02.phx.gbl...
>I need to store information in a 2 dimensional array. I understand
>ArrayList only works for a single dimensional array, is that correct ?
> So, I use the 2 dimensional array like in VB6. I pass the array into a
> subroutine, and inside it I "Redim Preserve" the array to increase the
> number of item in the array. I got the error "Redim statement requires an
> array", but arr is an array. HOw can I fix this problem ? Or, how can I do
> ArrayList for 2 dimensional array ?
> THank you very much.
>
> Private arr(COM_MAX, 0) As String
> LoadArr(arr)
>
> Sub LoadArr(ByRef arr As Array)

Pass it in the same way you define the array, eg

> Sub LoadArr(ByRef arr As int(,))

BTW, redim preserve does a complete copy of every element in the array every
time it's called. In your loop that will mean half a million copies for each
column.

Michael
Author
21 Nov 2006 1:48 AM
RobinS
Michael C is right about the Redim Preserve. I wouldn't do that.
I'd use an arraylist or a generic list (depending on what version
of .Net you're using.)

Robin S.
---------------------------------
Show quoteHide quote
"Michael C" <nospam@nospam.com> wrote in message
news:uneBdwPDHHA.4256@TK2MSFTNGP04.phx.gbl...
> "fniles" <fni***@pfmail.com> wrote in message
> news:OlkQffPDHHA.652@TK2MSFTNGP02.phx.gbl...
>>I need to store information in a 2 dimensional array. I understand
>>ArrayList only works for a single dimensional array, is that correct ?
>> So, I use the 2 dimensional array like in VB6. I pass the array into a
>> subroutine, and inside it I "Redim Preserve" the array to increase the
>> number of item in the array. I got the error "Redim statement requires an
>> array", but arr is an array. HOw can I fix this problem ? Or, how can I
>> do ArrayList for 2 dimensional array ?
>> THank you very much.
>>
>> Private arr(COM_MAX, 0) As String
>> LoadArr(arr)
>>
>> Sub LoadArr(ByRef arr As Array)
>
> Pass it in the same way you define the array, eg
>
>> Sub LoadArr(ByRef arr As int(,))
>
> BTW, redim preserve does a complete copy of every element in the array
> every time it's called. In your loop that will mean half a million copies
> for each column.
>
> Michael
>
Author
21 Nov 2006 2:31 AM
Michael C
"RobinS" <RobinS@NoSpam.yah.none> wrote in message
news:LpSdnd6f97hwx__YnZ2dnUVZ_smdnZ2d@comcast.com...
> Michael C is right about the Redim Preserve. I wouldn't do that.
> I'd use an arraylist or a generic list (depending on what version
> of .Net you're using.)

Or redim at the start or redim at set intervals.

Michael
Author
21 Nov 2006 8:21 AM
guy
why not have an Arraylist (or preferably a generic List(of T)) of Arraylists?

guy

Show quoteHide quote
"fniles" wrote:

> I need to store information in a 2 dimensional array. I understand ArrayList
> only works for a single dimensional array, is that correct ?
> So, I use the 2 dimensional array like in VB6. I pass the array into a
> subroutine, and inside it I "Redim Preserve" the array to increase the
> number of item in the array. I got the error "Redim statement requires an
> array", but arr is an array. HOw can I fix this problem ? Or, how can I do
> ArrayList for 2 dimensional array ?
> THank you very much.
>
> Private arr(COM_MAX, 0) As String
> LoadArr(arr)
>
> Sub LoadArr(ByRef arr As Array)
> lNumComm = 0
> For x = 1 to 1000
> ReDim Preserve arr(COM_MAX, lNumComm)--->Redim statement requires an array
> :
> next
>
>
>
Author
21 Nov 2006 2:27 PM
fniles
Thank you everybody.
I would like to use ArrayList, but it does not work with 2 dimensional
array, does it ?
How can I have a 2 dimensional array ArrayList ?

Show quoteHide quote
"guy" <g**@discussions.microsoft.com> wrote in message
news:78C271E1-2699-438E-ACF0-19FB1E7FF7CA@microsoft.com...
> why not have an Arraylist (or preferably a generic List(of T)) of
> Arraylists?
>
> guy
>
> "fniles" wrote:
>
>> I need to store information in a 2 dimensional array. I understand
>> ArrayList
>> only works for a single dimensional array, is that correct ?
>> So, I use the 2 dimensional array like in VB6. I pass the array into a
>> subroutine, and inside it I "Redim Preserve" the array to increase the
>> number of item in the array. I got the error "Redim statement requires an
>> array", but arr is an array. HOw can I fix this problem ? Or, how can I
>> do
>> ArrayList for 2 dimensional array ?
>> THank you very much.
>>
>> Private arr(COM_MAX, 0) As String
>> LoadArr(arr)
>>
>> Sub LoadArr(ByRef arr As Array)
>> lNumComm = 0
>> For x = 1 to 1000
>> ReDim Preserve arr(COM_MAX, lNumComm)--->Redim statement requires an
>> array
>> :
>> next
>>
>>
>>
Author
21 Nov 2006 10:02 PM
Michael C
"fniles" <fni***@pfmail.com> wrote in message
news:uDn0VlXDHHA.3660@TK2MSFTNGP06.phx.gbl...
> Thank you everybody.
> I would like to use ArrayList, but it does not work with 2 dimensional
> array, does it ?
> How can I have a 2 dimensional array ArrayList ?

You can put an array into each element of the arraylist I guess. Although
there is nothing wrong with using Redim Preserve if you limit it's use by
increasing the size of the array, say, every 1000 elements.

Michael