469,366 Members | 2,322 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,366 developers. It's quick & easy.

Two Dimensional Dynamic Array in VB.net

10
Hi all,
I'm looking for a way to create two dimentional dynamic array of type object in vb.net desktop application.

I know how to create a normal dynamic array:-

Dim MyArr As New System.Collections.ArrayList
MyArr.Add("Name")
MyArr.Add("Age")

I'll be waiting for your reply.

Kind regards,
Yahya
May 24 '07 #1
8 43041
kenobewan
4,871 Expert 4TB
I don't understand your question? How is a normal array not 2 dimensional?
May 24 '07 #2
TRScheel
638 Expert 512MB
Hi all,
I'm looking for a way to create two dimentional dynamic array of type object in vb.net desktop application.

I know how to create a normal dynamic array:-

Dim MyArr As New System.Collections.ArrayList
MyArr.Add("Name")
MyArr.Add("Age")

I'll be waiting for your reply.

Kind regards,
Yahya
So you are looking to make an array of arrays?

Expand|Select|Wrap|Line Numbers
  1. Dim MyArr As New System.Collections.ArrayList
  2. Dim ChildArr as New System.Collections.ArrayList
  3. MyArr.Add(ChildArr)
Shouldn't that work?
May 24 '07 #3
Plater
7,872 Expert 4TB
A normal array is single-dimensioned (don't think math, thing coding)
Single dimension (x)
[0][1][2][3][4][5][6][7][8][9]

Two-dimensions (x,y)
[0,0][1,0][2,0][3,0][4,0]
[0,1][1,1][2,1][3,1][4,1]

you could make an arraylist of arraylist, but I think there might be better alternatives
May 24 '07 #4
TRScheel
638 Expert 512MB
A normal array is single-dimensioned (don't think math, thing coding)
Single dimension (x)
[0][1][2][3][4][5][6][7][8][9]

Two-dimensions (x,y)
[0,0][1,0][2,0][3,0][4,0]
[0,1][1,1][2,1][3,1][4,1]

you could make an arraylist of arraylist, but I think there might be better alternatives
Indeed there are...

An array of objects is almost always a better choice (ie, an array of a struct or class).
May 24 '07 #5
yahya30
10
Indeed there are...

An array of objects is almost always a better choice (ie, an array of a struct or class).
I mean by normal array: - The single dimentional array as you know.

No one of you has provided me with a solution for this problem till now, you suggested to make an array of arrays, but how this could be done by code.

You have replied saying that making an array of arrays is the solution by doing this:-

Dim MyArr As New System.Collections.ArrayList
Dim ChildArr as New System.Collections.ArrayList
MyArr.Add(ChildArr) ' Please note that it should be MyArr.AddRange(ChildArr) because you are adding an object that contains a list of items, you are not adding just a single item. Anyhow I'm not convinced by this solution so far, so could you please clarify your point of view.


Kind regards,
Yahya
May 29 '07 #6
Plater
7,872 Expert 4TB
You want something addressable like:
myarrayobject[0][2].ToString();
Or something like that right? I am pretty sure there are objects in the System.Collection and System.Collection.Specialized that will handle that.
May 29 '07 #7
SammyB
807 Expert 512MB
Hi all,
I'm looking for a way to create two dimentional dynamic array of type object in vb.net desktop application.

I know how to create a normal dynamic array:-

Dim MyArr As New System.Collections.ArrayList
MyArr.Add("Name")
MyArr.Add("Age")

I'll be waiting for your reply.

Kind regards,
Yahya
What VB are you using, 2003 or 2005? There is a lot of overhead with ArrayLists, if you can use 2005, generics is a much better option. What are you trying to do? If you describe the problem, we may be able to devise a good data structure for you.
May 29 '07 #8
yahya30
10
So you are looking to make an array of arrays?

Expand|Select|Wrap|Line Numbers
  1. Dim MyArr As New System.Collections.ArrayList
  2. Dim ChildArr as New System.Collections.ArrayList
  3. MyArr.Add(ChildArr)
Shouldn't that work?

Yes I got you now, I did understand your code snippet. To clarify your description I'll write:-

Dim MyArr As New System.Collections.ArrayList
Dim ChildArr as New System.Collections.ArrayList
MyArr.Add(ChildArr) 'This will add the array "ChildArr" to the first row of "MyArr". Therfore if ChildArr contains the following items: C1,C2,C3 then "MyArr" will contain C1,C2,C3 in its first row.

Now if you want to add another items to the second row of "MyArr", then you should define another array for say "ChildArr2" and add it to "MyArr" by writing: -

Dim ChildArr2 as New System.Collections.ArrayList
ChildArr2.Add("CA1")
ChildArr2.Add("CA2")
ChildArr2.Add("CA3")
MyArr.Add(ChildArr2) ' This will add the array of "ChildArr2" into the second row in "MyArr", so if "ChildArr2" contains the following items: CA1, CA2, CA3 then "MyArr" will contain CA1, CA2, CA3 in its second row.

This means that you will get a two dimensional dynamic array of type object called "MyArr" that has two rows and three columns with the data of : -

C1, C2, C3
CA1, CA2, CA3

Therefore for each row you should define a new dynamic array to be added to that row ----- etc.

This is what you mean, isn't it?

Note: For the guy asking about my .net version, I'm using 2003

Thank you Mr. TRScheel for your help.


Kind regards,
Yahya
May 29 '07 #9

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

6 posts views Thread by Vasileios Zografos | last post: by
11 posts views Thread by fivelitermustang | last post: by
4 posts views Thread by Linda | last post: by
60 posts views Thread by Peter Olcott | last post: by
1 post views Thread by CARIGAR | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.