Structures inside structures

  • Thread starter Thread starter Andrew
  • Start date Start date
A

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;
 
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
 
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
 
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



roidy said:
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 said:
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;
 
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



roidy said:
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 said:
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;
 
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
 
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
 
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
 
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
 
Back
Top