473,480 Members | 1,833 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how to make array of arrays?

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
9 1576
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
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
2417
by: M.Siler | last post by:
<HTML> <HEAD> <TITLE></TITLE> <SCRIPT> <!-- var factor_val = new Array(8,7) factor_val = 68.8 factor_val = 55
58
10038
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
104
16842
by: Leszek | last post by:
Hi. Is it possible in javascript to operate on an array without knowing how mamy elements it has? What i want to do is sending an array to a script, and this script should add all values from...
24
3392
by: Michael | last post by:
Hi, I am trying to pass a function an array of strings, but I am having trouble getting the indexing to index the strings rather than the individual characters of one of the strings. I have...
57
3188
by: buuuuuum | last post by:
why array can't be assigned, like structs?
17
7208
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hi Gurus, I need to transfer a jagged array of byte by reference to unmanaged function, The unmanaged code should changed the values of the array, and when the unmanaged function returns I need...
14
12384
by: dan | last post by:
I would like to have the preprocessor automatically generate the number of array elements requested. Each element is zero. The elements get pasted into a larger array. The other elements may be...
1
3084
by: chiefychf | last post by:
I'm working on a school project and I am having a few issues... The program calls for three arrays a,b,c that have to be sorted, then compared to even or odd and stored in arrays d & e, then merge...
9
4462
by: Slain | last post by:
I need to convert a an array to a multidimensional one. Since I need to wrok with existing code, I need to modify a declaration which looks like this In the .h file int *x; in a initialize...
0
7049
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
7052
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,...
1
6744
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
5348
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
4790
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
3000
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
2989
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
565
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
188
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.