473,513 Members | 6,210 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 4378
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 multidimensional,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.com> wrote in message
news:OB**************@TK2MSFTNGP12.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.com> wrote in message
news:OB**************@TK2MSFTNGP12.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.com> 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*********@btopenworld.com> wrote in message
news:cd**********@titan.btinternet.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)(index)
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*********@btopenworld.com> wrote in message
news:cd**********@titan.btinternet.com...
Dim vArray()() As Integer
ReDim vArray(10)(20)
vArray(10)(10) = 10 ' etc..
___________________________________
The Grim Reaper

"rguti" <te**@test.com> wrote in message
news:OB**************@TK2MSFTNGP12.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*********@btopenworld.com> wrote in message
news:cd**********@titan.btinternet.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*****@hotmail.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
Because you can't define a jagged array using Dim vArray(10, 10), as
Herfried said.
I also agree with Cor - I very rarely use an array of more than one
dimension, it makes much more sense in most situations to use collections,
arraylist, hashtables or customised collection classes.
_________________________________
The Grim Reaper

"Ricky W. Hunt" <rh*****@hotmail.com> wrote in message
news:xi5Kc.111185$XM6.59523@attbi_s53...
"The Grim Reaper" <gr*********@btopenworld.com> wrote in message
news:cd**********@titan.btinternet.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 #11
Like I said..... I don't usually use arrays.
I simply tried to create a mulidimensional array in the IDE and that's the
syntax that worked.
Sorry.
_________________________________
The Grim Reaper

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:OS**************@TK2MSFTNGP09.phx.gbl...
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)(index)
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*********@btopenworld.com> wrote in message
news:cd**********@titan.btinternet.com...
Dim vArray()() As Integer
ReDim vArray(10)(20)
vArray(10)(10) = 10 ' etc..
___________________________________
The Grim Reaper

"rguti" <te**@test.com> wrote in message
news:OB**************@TK2MSFTNGP12.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 #12
Doh!
Here is the link to the article:

http://msdn.microsoft.com/library/de...et6_update.asp

Jay

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:OS**************@TK2MSFTNGP09.phx.gbl...
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)(index)
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*********@btopenworld.com> wrote in message
news:cd**********@titan.btinternet.com...
Dim vArray()() As Integer
ReDim vArray(10)(20)
vArray(10)(10) = 10 ' etc..
___________________________________
The Grim Reaper

"rguti" <te**@test.com> wrote in message
news:OB**************@TK2MSFTNGP12.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 #13
Ricky,
In addition to Herfried's & Grim's comments. See my other posts in this
thread:
Dim vArray()() As Integer
is a jagged or ragged or ragged-row array, while
Dim vArray(10, 20) As Integer is a two-dimensional array.

Hope this helps
Jay

"Ricky W. Hunt" <rh*****@hotmail.com> wrote in message
news:xi5Kc.111185$XM6.59523@attbi_s53... "The Grim Reaper" <gr*********@btopenworld.com> wrote in message
news:cd**********@titan.btinternet.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 #14
"Cor Ligthert" <no**********@planet.nl> wrote in message
news:O$*************@TK2MSFTNGP10.phx.gbl...
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?


OK. So this is only for "reusing" the name/memory and resizing it? If it's a
static array that never changes size there's no need to Redim? Thanks.
Nov 20 '05 #15
Ricky,
You are correct.

However! ReDim is handy in the constructor of a class also, where you do not
know the size of the array when you define the class, you only know the size
when you create an instance of the class.

Something like:

Public Class MyBuffer

Private m_buffer() As Byte

Public Sub New(count As Integer)
ReDim m_buffer(count - 1)
End Sub

End Class

Dim b1 As New MyBuffer(10)
Dim b2 As New MyBuffer(20)

Hope this helps
Jay

"Ricky W. Hunt" <rh*****@hotmail.com> wrote in message
news:OwcKc.114218$Oq2.90853@attbi_s52...
"Cor Ligthert" <no**********@planet.nl> wrote in message
news:O$*************@TK2MSFTNGP10.phx.gbl...
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?


OK. So this is only for "reusing" the name/memory and resizing it? If it's

a static array that never changes size there's no need to Redim? Thanks.

Nov 20 '05 #16
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
Ricky,
You are correct.

However! ReDim is handy in the constructor of a class also, where you do not know the size of the array when you define the class, you only know the size when you create an instance of the class.


Thanks.
Nov 20 '05 #17

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

Similar topics

2
7649
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 =...
2
2865
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...
3
30645
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...
60
10094
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: >...
22
2249
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...
6
2263
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...
8
11787
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...
272
13880
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...
5
3865
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...
0
7254
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
7153
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
7373
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,...
0
5677
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,...
1
5079
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3230
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...
0
3218
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1585
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 ...
1
796
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.