Groups | Blog | Home
all groups > vb.net > november 2006 >

vb.net : 2 dimensional array question


fniles
11/20/2006 5:00:57 PM
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

RobinS
11/20/2006 5:48:24 PM
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.
---------------------------------
[quoted text, click to view]

guy
11/21/2006 12:21:02 AM
why not have an Arraylist (or preferably a generic List(of T)) of Arraylists?

guy

[quoted text, click to view]
fniles
11/21/2006 8:27:36 AM
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 ?

[quoted text, click to view]

Michael C
11/21/2006 10:36:45 AM
[quoted text, click to view]

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

[quoted text, click to view]

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

Michael C
11/21/2006 1:31:19 PM
[quoted text, click to view]

Or redim at the start or redim at set intervals.

Michael

Michael C
11/22/2006 9:02:14 AM
[quoted text, click to view]

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

AddThis Social Bookmark Button