473,763 Members | 8,423 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

creating a two dimensional array

Hi,

How do I create a two dimensional array?

I have created a one dimensional doing this:

Dim laFields As ArrayList = New ArrayList

How about to do a 2 dimensional?

Thanks.
Nov 20 '05 #1
16 4409
What you have created is an arraylist.

I don't think arraylists do two dimensions inherently.
It think the idea is to add objects to the array --which is just a glorified
collection.

Your objects then have all of the properties that you need in themselves so
you don't need multiple dimensions.

If however you want a multidimensiona l,actual array in VB

dim x(2,3,4) as integer

will give you a 3 dimensional array of integers.

depends on what you want to accomplish.

HTH,

Shane
"rguti" <te**@test.co m> wrote in message
news:OB******** ******@TK2MSFTN GP12.phx.gbl...
Hi,

How do I create a two dimensional array?

I have created a one dimensional doing this:

Dim laFields As ArrayList = New ArrayList

How about to do a 2 dimensional?

Thanks.

Nov 20 '05 #2
Dim vArray()() As Integer
ReDim vArray(10)(20)
vArray(10)(10) = 10 ' etc..
_______________ _______________ _____
The Grim Reaper

"rguti" <te**@test.co m> wrote in message
news:OB******** ******@TK2MSFTN GP12.phx.gbl...
Hi,

How do I create a two dimensional array?

I have created a one dimensional doing this:

Dim laFields As ArrayList = New ArrayList

How about to do a 2 dimensional?

Thanks.

Nov 20 '05 #3
* rguti <te**@test.co m> scripsit:
How do I create a two dimensional array?

I have created a one dimensional doing this:

Dim laFields As ArrayList = New ArrayList
That's not an array, that's an arraylist.
How about to do a 2 dimensional?


\\\
Dim aint(99, 99) As Integer
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #4

"The Grim Reaper" <gr*********@bt openworld.com> wrote in message
news:cd******** **@titan.btinte rnet.com...
Dim vArray()() As Integer
ReDim vArray(10)(20)
vArray(10)(10) = 10 ' etc..


Assuming that's even allowed syntax, you've got an array of arrays, not a
2-dimensional array.
Nov 20 '05 #5
Grim,
As Jeff suggests, you created an array of arrays (also referred to as a
Ragged or Ragged-Row Array), which is slightly different then a 2
dimensional array.

To create a 2 dimensional array 10 x 20 (11 x 21 really) you would need to
use Herfrieds or SStory's syntax of:

Dim vArray(,) As Integer
Redim vArray(10, 20)

An array of array is called a ragged array because each row does not need to
be the same length! (The ends of the rows are ragged, they don't line up).

Dim vArray()() As Integer
' size the outer array
Redim vArray(10)

For index As Integer = 0 to 10
' size each of the inner arrays
Redim vArray(index)(i ndex)
Next

Where we have an array of arrays, where each row is 1 column longer then the
previous row.

The following article does a good job of describing the various kinds of
arrays in .NET.

Hope this helps
Jay
"The Grim Reaper" <gr*********@bt openworld.com> wrote in message
news:cd******** **@titan.btinte rnet.com...
Dim vArray()() As Integer
ReDim vArray(10)(20)
vArray(10)(10) = 10 ' etc..
_______________ _______________ _____
The Grim Reaper

"rguti" <te**@test.co m> wrote in message
news:OB******** ******@TK2MSFTN GP12.phx.gbl...
Hi,

How do I create a two dimensional array?

I have created a one dimensional doing this:

Dim laFields As ArrayList = New ArrayList

How about to do a 2 dimensional?

Thanks.


Nov 20 '05 #6
Jay,
The following article does a good job of describing the various kinds of
arrays in .NET.

I did not see the link to the article in in the message.

I probably will not use it however I attent you on it because if someone
starts to Google this thread

Cor
Nov 20 '05 #7
"The Grim Reaper" <gr*********@bt openworld.com> wrote in message
news:cd******** **@titan.btinte rnet.com...
Dim vArray()() As Integer
ReDim vArray(10)(20)


I'm new to VB and I don't understand this ReDim. Why not just do a:

Dim vArray(10, 20) As Integer

and be done with it?
Nov 20 '05 #8
Hi Ricky,

A redim is a redimension of your array, as soon as you have to use it, than
it is better to look to a Net collection (not the VB one) to use or to make
your own class for it or to make an arraylist of your own class objects.

I hope this helps?

Cor
Nov 20 '05 #9
* Ricky W. Hunt <rh*****@hotmai l.com> scripsit:
Dim vArray()() As Integer
ReDim vArray(10)(20)


I'm new to VB and I don't understand this ReDim. Why not just do a:

Dim vArray(10, 20) As Integer

and be done with it?


This would create a 2-dimensional array, not a jagged array.

For information to 'ReDim', place the caret on it and press F1.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
7669
by: ip4ram | last post by:
I used to work with C and have a set of libraries which allocate multi-dimensional arrays(2 and 3) with single malloc call. data_type **myarray = (data_type**)malloc(widht*height*sizeof(data_type)+ height* sizeof(data_type*)); //allocate individual addresses for row pointers. Now that I am moving to C++,am looking for something by which I can
2
2897
by: George Marsaglia | last post by:
I have a set of, say, 2000 points in the 8-dimensional simplex S={(x_1,x_2,...,x_8),x_1+x_2+...+x_8=1, x's>=0}. To help analyze that 8-dimensional set, I wish to project the set of points onto each of the 'faces' {x_i+x_j+x_k=1} for the 56 choices i,j,k, that is, i=1 to 6; j=i+1 to 7; k=j+1 to 8. Finally, use gnuplot to load and plot each of the 56 files of 3-d points. I have C code that will, for given i,j,k, find the projection...
3
30658
by: ZeroVisio | last post by:
Hi, Is it possible to create two -dimensional array using ArrayList in C#? I know you can do one-dimensional array but i dont know how to do two-dimensional. in my case my number of columns remain same, but # of rows are variable. Right now I'm using DataTable for this but my feeling is it is not very efficient and may cause some problems. if you have done something like this before could you please tell me how to do this or if using...
60
10184
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: > http://groups.google.com/group/comp.lang.c++/msg/db577c43260a5310?hl > >Another way is to create a one dimensional array and handle the >indexing yourself (index = row * row_size + col). This is readily >implemented in template classes that can create dynamically allocated >multi-dimensional...
22
2292
by: spam.noam | last post by:
Hello, I discovered that I needed a small change to the Python grammar. I would like to hear what you think about it. In two lines: Currently, the expression "x" is a syntax error. I suggest that it will be evaluated like "x", just as "x" is evaluated like "x" right now.
6
2279
by: fniles | last post by:
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...
8
11829
by: per9000 | last post by:
Hi all, I have a two-dimensional array of data, f.x int's. We can imagine that the array is "really large". Now I want the data in it and store this in a one-dimensional array. The obvious way to do this is a nested for-loop - but we all know O(n^2) is bad. So I am looking for something like ArrayList.ToArray(), or Matlabs A(:). C#
272
14145
by: Peter Olcott | last post by:
http://groups.google.com/group/comp.lang.c++/msg/a9092f0f6c9bf13a I think that the operator() member function does not work correctly, does anyone else know how to make a template for making two dimensional arrays from std::vectors ??? I want to use normal Array Syntax.
5
3886
by: nelly0 | last post by:
developing a program that will manipulate noise levels (measured in decibels) that is collected by car manufacturers. These noise levels are produced at seven different speeds by a maximum of six different models of cars that are produced by the car manufacturer. Task 1 Step 1: Create a directory called Assignment02 and create the files of steps 2, 3 and 4 in this directory as well as your project file. Step 2: Create a file called...
0
9564
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10148
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10002
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9938
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9823
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8822
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5270
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3917
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.