Arrays of structures that contain an array - is it even possible??

J

John Dann

Is it possible in VB.net to have arrays of structures (ie UDTs) where
the structure definition includes one or more arrays? Something like:

Structure MyUDT
ItemOne () as byte 'for example
sub new(byval dimension as integer)
redim itemone(dimension)
end sub
End structure

dim MyArray as myudt = new myudt(n)
' where n is known
'This works, but

dim Myarray() as myudt = new myudt(n)

gives a design-time error even before redimming the array.

I've got 3 options:

1. I can no longer have this sort of UDT array in VB.net (I'm sure I
used to have something similar working in VB6).

2. It is possible but needs a different syntax/declaration.

3. It is possible and the syntax above ought to work, but I've made a
mistake in my own code (the real UDT is much more complicated than the
example above and includes several such arrays in the UDT definition.
Though I've checked it's still possible that there might be a
typing/coding error).

Any help with this would be much appreciated - it's a key part of a
current project.

John Dann
 
K

Ken Tucker [MVP]

Hi,

The problem with code is that you want to create an unknown amount of
myudt. If you don’t know the size of myarray why don’t you look into
storing myudt in an Arraylist or collection.

Ken
==========
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top