By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,693 Members | 1,255 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,693 IT Pros & Developers. It's quick & easy.

how to make array of arrays?

P: n/a
Hello,

I created a structure ABC and an array of type ABC

Public Structure ABC
Dim str1 As String
Dim int1 As Integer
End Structure

Public ABC1 As New ABC, ABC2 As New ABC
Public ABC3 As New ABC, ABC4 As New ABC
Public arrABC1() As ABC = {ABC1, ABC2}'--this array OK
Public arrABC2() As ABC = {ABC3, ABC4}'--this array OK

Now I want to place arrABC1 and arrABC2 into an array.
How to do this? I tried

Public arrABC() As ABC = {arrABC1(1), arrABC2(1)}'--ok

and call it like this

....arrABC(0)(0) to access structure ABC1 -- Not OK here

but I get an error message that I can't do this because
Structure ABC has no default property (option strict on -
must remain on). I could either add a default property to
the structure (how do you do that?) or I could use a
different kind of array type object. I have tried
ArrayList, but that did not work. I tried an Object()
array, but that did not work. Any suggestions appreciated.

Thanks,
Steve
Nov 21 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
Steve,
Public arrABC() As ABC = {arrABC1(1), arrABC2(1)}'--ok No! you defined an array of ABC, not an array of array of ABC. arrABC has
ABC1 & ABC3 in it.

Try:

Public arrABC()() As ABC = {arrABC1, arrABC2}

Then will work:
Dim a As ABC = arrABC(0)(0)

Hope this helps
Jay

"Steve" <an*******@discussions.microsoft.com> wrote in message
news:45****************************@phx.gbl... Hello,

I created a structure ABC and an array of type ABC

Public Structure ABC
Dim str1 As String
Dim int1 As Integer
End Structure

Public ABC1 As New ABC, ABC2 As New ABC
Public ABC3 As New ABC, ABC4 As New ABC
Public arrABC1() As ABC = {ABC1, ABC2}'--this array OK
Public arrABC2() As ABC = {ABC3, ABC4}'--this array OK

Now I want to place arrABC1 and arrABC2 into an array.
How to do this? I tried

Public arrABC() As ABC = {arrABC1(1), arrABC2(1)}'--ok

and call it like this

...arrABC(0)(0) to access structure ABC1 -- Not OK here

but I get an error message that I can't do this because
Structure ABC has no default property (option strict on -
must remain on). I could either add a default property to
the structure (how do you do that?) or I could use a
different kind of array type object. I have tried
ArrayList, but that did not work. I tried an Object()
array, but that did not work. Any suggestions appreciated.

Thanks,
Steve

Nov 21 '05 #2

P: n/a
Yes! Thank you very much. I just figured that out before
I got to the post. You concur!

Thanks for your reply.
Steve
-----Original Message-----
Steve,
Public arrABC() As ABC = {arrABC1(1), arrABC2(1)}'--okNo! you defined an array of ABC, not an array of array of

ABC. arrABC hasABC1 & ABC3 in it.

Try:

Public arrABC()() As ABC = {arrABC1, arrABC2}

Then will work:
Dim a As ABC = arrABC(0)(0)

Hope this helps
Jay

"Steve" <an*******@discussions.microsoft.com> wrote in messagenews:45****************************@phx.gbl...
Hello,

I created a structure ABC and an array of type ABC

Public Structure ABC
Dim str1 As String
Dim int1 As Integer
End Structure

Public ABC1 As New ABC, ABC2 As New ABC
Public ABC3 As New ABC, ABC4 As New ABC
Public arrABC1() As ABC = {ABC1, ABC2}'--this array OK
Public arrABC2() As ABC = {ABC3, ABC4}'--this array OK

Now I want to place arrABC1 and arrABC2 into an array.
How to do this? I tried

Public arrABC() As ABC = {arrABC1(1), arrABC2(1)}'--ok

and call it like this

...arrABC(0)(0) to access structure ABC1 -- Not OK here

but I get an error message that I can't do this because
Structure ABC has no default property (option strict on - must remain on). I could either add a default property to the structure (how do you do that?) or I could use a
different kind of array type object. I have tried
ArrayList, but that did not work. I tried an Object()
array, but that did not work. Any suggestions appreciated.
Thanks,
Steve

.

Nov 21 '05 #3

P: n/a
Doh!
Public arrABC() As ABC = {arrABC1(1), arrABC2(1)}'--ok No! you defined an array of ABC, not an array of array of ABC. arrABC has
ABC1 & ABC3 in it.

Damn based 0 indexes ;-) Your arrABC has ABC2 & ABC4 in it...

Glad you got it to work.

Hope this helps
Jay
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:u2**************@TK2MSFTNGP11.phx.gbl... Steve,
Public arrABC() As ABC = {arrABC1(1), arrABC2(1)}'--ok

No! you defined an array of ABC, not an array of array of ABC. arrABC has
ABC1 & ABC3 in it.

Try:

Public arrABC()() As ABC = {arrABC1, arrABC2}

Then will work:
Dim a As ABC = arrABC(0)(0)

Hope this helps
Jay

"Steve" <an*******@discussions.microsoft.com> wrote in message
news:45****************************@phx.gbl...
Hello,

I created a structure ABC and an array of type ABC

Public Structure ABC
Dim str1 As String
Dim int1 As Integer
End Structure

Public ABC1 As New ABC, ABC2 As New ABC
Public ABC3 As New ABC, ABC4 As New ABC
Public arrABC1() As ABC = {ABC1, ABC2}'--this array OK
Public arrABC2() As ABC = {ABC3, ABC4}'--this array OK

Now I want to place arrABC1 and arrABC2 into an array.
How to do this? I tried

Public arrABC() As ABC = {arrABC1(1), arrABC2(1)}'--ok

and call it like this

...arrABC(0)(0) to access structure ABC1 -- Not OK here

but I get an error message that I can't do this because
Structure ABC has no default property (option strict on -
must remain on). I could either add a default property to
the structure (how do you do that?) or I could use a
different kind of array type object. I have tried
ArrayList, but that did not work. I tried an Object()
array, but that did not work. Any suggestions appreciated.

Thanks,
Steve


Nov 21 '05 #4

P: n/a
Steve,

In addition to Jay,

A very easy way of making an array of arrays is using the arraylist.

And than use the directcast when you are using it.

When you want a example of that tell that.

Cor
Nov 21 '05 #5

P: n/a
Thanks. Yes. How would you cast this using Arraylists?

I tried arraylist with no luck

Dim arrL() As New ArrayList
arrl(1) = CType(ABC1(x), ABC)
arrl(2) = CType(ABC2(x), ABC)
....

something like that? Is there a benefit to using
ArrayLists over just creating an Array of Type ABC?

-----Original Message-----
Steve,

In addition to Jay,

A very easy way of making an array of arrays is using the arraylist.
And than use the directcast when you are using it.

When you want a example of that tell that.

Cor
.

Nov 21 '05 #6

P: n/a
Steve,

Here 2 samples of me, The first is arraylist array, where is some
explaination the second an arraylist arraylist

When the array is static, than you can (should) use the standard Array, when
the array is dynamic you should in my opinion never take the standard Array

I hope they help?

Cor

\\\arraylist array
Option Strict On
Public Module Main
' Sample of an arraylist that itself contains 10 classic arrays.
Public Sub Main()
Dim x As New ArrayList
Dim y() As Integer = {1, 2, 3, 4}
For i As Integer = 0 To 9
x.Add(y)
Next
MessageBox.Show(DirectCast(x(9), IList)(2).ToString)
'With option strict off you do not
'have to use the directcast and than it is
'MessageBox.Show(a(2)(2).ToString) 'but I would not do that
'I show this above to make it more classic looking for you.
'The Insert
Dim yN() As Integer = {5, 6, 7, 8}
x.Insert(1, yN)
MessageBox.Show(DirectCast(x(1), IList)(2).ToString)
End Sub
End Module
///
\\\arraylist arraylist
Dim x As New ArrayList
For i As Integer = 0 To 9
Dim y As New ArrayList
For j As Integer = 0 To 4
y.Add(Chr(j + 65))
Next
x.Add(y)
Next
MessageBox.Show(DirectCast(x(2), ArrayList)(2).ToString)
Dim yN As New ArrayList
For j As Integer = 0 To 4
yN.Add(Chr(j + 75))
Next
x.Insert(1, yN)
MessageBox.Show(DirectCast(x(1), ArrayList)(2).ToString)
///
"Steve" <an*******@discussions.microsoft.com>
Thanks. Yes. How would you cast this using Arraylists?

I tried arraylist with no luck

Dim arrL() As New ArrayList
arrl(1) = CType(ABC1(x), ABC)
arrl(2) = CType(ABC2(x), ABC)
...

something like that? Is there a benefit to using
ArrayLists over just creating an Array of Type ABC?

-----Original Message-----
Steve,

In addition to Jay,

A very easy way of making an array of arrays is using

the arraylist.

And than use the directcast when you are using it.

When you want a example of that tell that.

Cor
.

Nov 21 '05 #7

P: n/a
Hi Cor,

Thanks for the example. So, to get this straight, if I do

ArrayList.Add(y)

that adds an element sequentially,

and

ArrayList.Insert(n, m)

adds an element at a selected index n?
-----Original Message-----
Steve,

Here 2 samples of me, The first is arraylist array, where is someexplaination the second an arraylist arraylist

When the array is static, than you can (should) use the standard Array, whenthe array is dynamic you should in my opinion never take the standard Array
I hope they help?

Cor

\\\arraylist array
Option Strict On
Public Module Main
' Sample of an arraylist that itself contains 10 classic arrays. Public Sub Main()
Dim x As New ArrayList
Dim y() As Integer = {1, 2, 3, 4}
For i As Integer = 0 To 9
x.Add(y)
Next
MessageBox.Show(DirectCast(x(9), IList) (2).ToString) 'With option strict off you do not
'have to use the directcast and than it is
'MessageBox.Show(a(2)(2).ToString) 'but I would not do that 'I show this above to make it more classic looking for you.'The Insert
Dim yN() As Integer = {5, 6, 7, 8}
x.Insert(1, yN)
MessageBox.Show(DirectCast(x(1), IList) (2).ToString) End Sub
End Module
///
\\\arraylist arraylist
Dim x As New ArrayList
For i As Integer = 0 To 9
Dim y As New ArrayList
For j As Integer = 0 To 4
y.Add(Chr(j + 65))
Next
x.Add(y)
Next
MessageBox.Show(DirectCast(x(2), ArrayList)(2).ToString)
Dim yN As New ArrayList
For j As Integer = 0 To 4
yN.Add(Chr(j + 75))
Next
x.Insert(1, yN)
MessageBox.Show(DirectCast(x(1), ArrayList)(2).ToString)
///
"Steve" <an*******@discussions.microsoft.com>
Thanks. Yes. How would you cast this using Arraylists?

I tried arraylist with no luck

Dim arrL() As New ArrayList
arrl(1) = CType(ABC1(x), ABC)
arrl(2) = CType(ABC2(x), ABC)
...

something like that? Is there a benefit to using
ArrayLists over just creating an Array of Type ABC?

-----Original Message-----
Steve,

In addition to Jay,

A very easy way of making an array of arrays is using

the arraylist.

And than use the directcast when you are using it.

When you want a example of that tell that.

Cor
.

.

Nov 21 '05 #8

P: n/a
Steve,

Try this maybe this is easier to understand.
However every row (arraylist) can be of a different lenght keep that in mind
\\\
Dim x As New ArrayList
For i As Integer = 0 To 9
Dim y As New ArrayList
For j As Integer = 0 To 4
y.Add("")
Next
x.Add(y)
Next
DirectCast(x(2), ArrayList)(2) = "Steve"
MessageBox.Show(DirectCast(x(2), ArrayList)(2).ToString)
////

I hope this helps?

Cor
Nov 21 '05 #9

P: n/a
Yes. Thank you. I think I'm getting it now. It is the
DirectCast part that I was missing before. Now I got it.

Thanks.

-----Original Message-----
Steve,

Try this maybe this is easier to understand.
However every row (arraylist) can be of a different lenght keep that in mind\\\
Dim x As New ArrayList
For i As Integer = 0 To 9
Dim y As New ArrayList
For j As Integer = 0 To 4
y.Add("")
Next
x.Add(y)
Next
DirectCast(x(2), ArrayList)(2) = "Steve"
MessageBox.Show(DirectCast(x(2), ArrayList)(2).ToString)
////

I hope this helps?

Cor
.

Nov 21 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.