PC Review


Reply
Thread Tools Rate Thread

creating a two dimensional array

 
 
rguti
Guest
Posts: n/a
 
      16th Jul 2004
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.


 
Reply With Quote
 
 
 
 
SStory
Guest
Posts: n/a
 
      16th Jul 2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.
>
>



 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      16th Jul 2004
* rguti <(E-Mail Removed)> 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/>
 
Reply With Quote
 
The Grim Reaper
Guest
Posts: n/a
 
      16th Jul 2004
Dim vArray()() As Integer
ReDim vArray(10)(20)
vArray(10)(10) = 10 ' etc..
___________________________________
The Grim Reaper

"rguti" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.
>
>



 
Reply With Quote
 
Jeff Johnson [MVP: VB]
Guest
Posts: n/a
 
      16th Jul 2004

"The Grim Reaper" <(E-Mail Removed)> wrote in message
news:cd999o$7b3$(E-Mail Removed)...

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


 
Reply With Quote
 
Jay B. Harlow [MVP - Outlook]
Guest
Posts: n/a
 
      16th Jul 2004
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" <(E-Mail Removed)> wrote in message
news:cd999o$7b3$(E-Mail Removed)...
> Dim vArray()() As Integer
> ReDim vArray(10)(20)
> vArray(10)(10) = 10 ' etc..
> ___________________________________
> The Grim Reaper
>
> "rguti" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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.
> >
> >

>
>



 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      17th Jul 2004
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


 
Reply With Quote
 
Ricky W. Hunt
Guest
Posts: n/a
 
      17th Jul 2004
"The Grim Reaper" <(E-Mail Removed)> wrote in message
news:cd999o$7b3$(E-Mail Removed)...
> 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?


 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      17th Jul 2004
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


 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      17th Jul 2004
* Ricky W. Hunt <(E-Mail Removed)> 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/>
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating a multi dimensional array using transpose - Is this the best answer? kimbroughton@westvirginia.com Microsoft Excel Programming 11 19th Jul 2006 05:28 PM
Creating a multi dimensional array =?Utf-8?B?RGlubw==?= Microsoft VB .NET 2 9th Nov 2005 05:39 PM
creating two-dimensional array... =?Utf-8?B?WmVyb1Zpc2lv?= Microsoft C# .NET 3 24th Mar 2005 08:01 PM
Creating datagrid view from an two-dimensional array mirek Microsoft C# .NET 4 23rd Nov 2004 08:42 PM
Creating and displaying a two dimensional array of picturebox Ahmed El-Daly Microsoft Dot NET Framework Forms 1 6th Aug 2003 01:55 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:47 PM.