Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / VB.NET / November 2006

Tip: Looking for answers? Try searching our database.

2 dimensional array question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
fniles - 20 Nov 2006 23:00 GMT
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
Michael C - 20 Nov 2006 23:36 GMT
>I need to store information in a 2 dimensional array. I understand
>ArrayList only works for a single dimensional array, is that correct ?
[quoted text clipped - 9 lines]
>
> 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
RobinS - 21 Nov 2006 01:48 GMT
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.
---------------------------------
>>I need to store information in a 2 dimensional array. I understand
>>ArrayList only works for a single dimensional array, is that correct ?
[quoted text clipped - 19 lines]
>
> Michael
Michael C - 21 Nov 2006 02:31 GMT
> 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
guy - 21 Nov 2006 08:21 GMT
why not have an Arraylist (or preferably a generic List(of T)) of Arraylists?

guy

> I need to store information in a 2 dimensional array. I understand ArrayList
> only works for a single dimensional array, is that correct ?
[quoted text clipped - 14 lines]
> :
> next
fniles - 21 Nov 2006 14:27 GMT
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 ?

> why not have an Arraylist (or preferably a generic List(of T)) of
> Arraylists?
[quoted text clipped - 22 lines]
>> :
>> next
Michael C - 21 Nov 2006 22:02 GMT
> 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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.