473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

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

Similar topics

6
by: Vasileios Zografos | last post by:
Hello, I have a function that generates some values (e.g. vertices in 2d space) the number of which I dont know. So, it could generate 20 vertices, 100 vertices, or even 1 vertex. void...
11
by: fivelitermustang | last post by:
Actually, how would I go about allocating a four-dimensional dynamic array? I only know how to make two dimensional dynamic arrays: double **v; v = new double*; for (int i=0; i<C; i++) { v =...
4
by: Linda | last post by:
How can I declare a two dimention array of character with dynamical first dimention and static second dimention using mix of pointer* and . I think "char *A" means first dimention is static and...
6
by: Jozef Jarosciak | last post by:
Quickest way to find the string in 1 dimensional string array! I have a queue 1 dimensional array of strings called 'queue' and I need a fast way to search it. Once there is match, I don't need...
60
by: Peter Olcott | last post by:
I need to know how to get the solution mentioned below to work. The solution is from gbayles Jan 29 2001, 12:50 pm, link is provided below: >...
3
by: Troy | last post by:
I have a dilemma where I am creating a dynamic two dimensional array and filling it with information from a .csv file. Unfortunately, later when I try to call that information back from the array...
4
by: singleb | last post by:
I've tryed to something lik this and got "Object reference not set to an instance of an object." Dim myarr(,) As String myarr(0, 0) = "aaaa" myarr(0, 1) = "bbbb" myarr(1, 0) = "cccc" myarr(1,...
11
by: C C++ C++ | last post by:
Hi all, got this interview question please respond. How can you quickly find the number of elements stored in a a) static array b) dynamic array ? Rgrds MA
1
by: ict027 | last post by:
i wanted to create a two dimensional dynamic array in vs.net . but it gives errors, this is the syntax i tried; Dim arrDen(,) As Integer(numOfEmp, nDen) i hope your suggestions to create...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.