473,748 Members | 10,569 Online
Bytes | Software Development & Data Engineering Community
+ 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 1590
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*******@disc ussions.microso ft.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*******@disc ussions.microso ft.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******** ******@TK2MSFTN GP11.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*******@disc ussions.microso ft.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).ToStr ing)
'With option strict off you do not
'have to use the directcast and than it is
'MessageBox.Sho w(a(2)(2).ToStr ing) '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).ToStr ing)
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).T oString)
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).T oString)
///
"Steve" <an*******@disc ussions.microso ft.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.Inser t(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.Sho w(a(2)(2).ToStr ing) '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.Sho w(DirectCast(x( 2), ArrayList)(2).T oString)
Dim yN As New ArrayList
For j As Integer = 0 To 4
yN.Add(Chr(j + 75))
Next
x.Insert(1, yN)
MessageBox.Sho w(DirectCast(x( 1), ArrayList)(2).T oString)
///
"Steve" <an*******@disc ussions.microso ft.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).T oString)
////

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.Sho w(DirectCast(x( 2), ArrayList)(2).T oString)
////

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
2458
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
10170
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 code... TCHAR myArray; DoStuff(myArray);
104
16997
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 that array Could you show me a little example how to do this? Thanks.
24
3455
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 declared an array as: char *stringArray = {"one","two","three","a"}; When I pass the array using:
57
3256
by: buuuuuum | last post by:
why array can't be assigned, like structs?
17
7253
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 to show the array data to the end user. Can I do that? How?
14
12445
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 non-zero. ***** Here is an example of what I need to do: #define YEAR_1 2005 #define YEAR_2 2007 #define YEARS (YEAR_2 - YEAR_1 + 1)
1
3121
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 a,b,c into another array f.. I can do two arrays, but I have issues when trying to do all three and when I do the even/odd compare I only get 2 numbers processed. here is some of the code... //*******************Function...
9
4500
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 function: x = new int;
0
8991
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
9548
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
9249
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
8244
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...
1
6796
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4607
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
4876
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2787
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2215
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.