Home All Groups Group Topic Archive Search About

Structures inside structures

Author
15 May 2009 6:23 AM
Andrew
Could somebody perhaps let me know, what the equivalnet code in VB.Net for
this C# example.

public struct MyStruct
    {
        public MyChild[] AsChild;
        public int nOther;
        public string nInfo;
    }


MyChild structure:

    private int nINTA;
    private string cSomeString;

Author
15 May 2009 8:34 AM
roidy
Pretty much the same...

Public Structure MyStruct
        Public Mychild() As Child
        Public nOther As Integer
        Public nInfo As String
End Structure

Structure Child
    Private nINTA As Integer
    Private cSomeString As String
End Structure

Rob

Show quoteHide quote
"Andrew" <And***@discussions.microsoft.com> wrote in message
news:E2BB0277-1117-4D40-ABB4-791DC7997B2F@microsoft.com...
> Could somebody perhaps let me know, what the equivalnet code in VB.Net for
> this C# example.
>
> public struct MyStruct
>    {
>        public MyChild[] AsChild;
>        public int nOther;
>        public string nInfo;
>    }
>
>
> MyChild structure:
>
>    private int nINTA;
>    private string cSomeString;
>
Author
16 May 2009 5:55 AM
Andrew
I thought so.
So, adding to this example, is this proper way to return the child structure.

Dim Parent As New MyStruct
Dim Child As New Child

Child = Parent.MyChild



Show quoteHide quote
"roidy" wrote:

> Pretty much the same...
>
> Public Structure MyStruct
>         Public Mychild() As Child
>         Public nOther As Integer
>         Public nInfo As String
> End Structure
>
> Structure Child
>     Private nINTA As Integer
>     Private cSomeString As String
> End Structure
>
> Rob
>
> "Andrew" <And***@discussions.microsoft.com> wrote in message
> news:E2BB0277-1117-4D40-ABB4-791DC7997B2F@microsoft.com...
> > Could somebody perhaps let me know, what the equivalnet code in VB.Net for
> > this C# example.
> >
> > public struct MyStruct
> >    {
> >        public MyChild[] AsChild;
> >        public int nOther;
> >        public string nInfo;
> >    }
> >
> >
> > MyChild structure:
> >
> >    private int nINTA;
> >    private string cSomeString;
> >
>
Author
16 May 2009 8:35 AM
roidy
Yep but don`t forget that MyChild is an array of type Child and must be
declared to the size you need:-

ReDim Parent.MyChild(10)

and then you must specify which one you want Child to become:-

Child = Parent.MyChild(0)

So the whole code looks like:-

Public Structure MyStruct
    Public Mychild() As Child
    Public nOther As Integer
    Public nInfo As String
End Structure

Structure Child
    Private nINTA As Integer
    Private cSomeString As String
End Structure

Dim Parent As New MyStruct
Dim Child As New Child
ReDim Parent.Mychild(10)    <--- However many you need

Child = Parent.Mychild(0)     <--- Index of the one you want to pass to
Child



Rob


Show quoteHide quote
"Andrew" <And***@discussions.microsoft.com> wrote in message
news:18C088EC-23F5-434C-9BA5-79A542D5A848@microsoft.com...
> I thought so.
> So, adding to this example, is this proper way to return the child
> structure.
>
> Dim Parent As New MyStruct
> Dim Child As New Child
>
> Child = Parent.MyChild
>
Author
17 May 2009 10:45 PM
Andrew
Ah, that's why I was getting array type errors. You wouldn't happen to be
able to tell me where you learned that from?
I have one more if you don't mind. How can I return the whole Parent.Mychild
structure into another structure like this:

Dim Husband As New MyStruct
Dim Wife As New MyStructA (imagine Mystruct is is the same as Mystruct)

Wife.MyChild = Husband.MyChild




Show quoteHide quote
"roidy" wrote:

> Yep but don`t forget that MyChild is an array of type Child and must be
> declared to the size you need:-
>
> ReDim Parent.MyChild(10)
>
> and then you must specify which one you want Child to become:-
>
> Child = Parent.MyChild(0)
>
> So the whole code looks like:-
>
> Public Structure MyStruct
>     Public Mychild() As Child
>     Public nOther As Integer
>     Public nInfo As String
> End Structure
>
> Structure Child
>     Private nINTA As Integer
>     Private cSomeString As String
> End Structure
>
> Dim Parent As New MyStruct
> Dim Child As New Child
> ReDim Parent.Mychild(10)    <--- However many you need
>
> Child = Parent.Mychild(0)     <--- Index of the one you want to pass to
> Child
>
>
>
> Rob
>
>
> "Andrew" <And***@discussions.microsoft.com> wrote in message
> news:18C088EC-23F5-434C-9BA5-79A542D5A848@microsoft.com...
> > I thought so.
> > So, adding to this example, is this proper way to return the child
> > structure.
> >
> > Dim Parent As New MyStruct
> > Dim Child As New Child
> >
> > Child = Parent.MyChild
> >

>
>