Structure within structure - Help needed [modified]
-
I am able to create a structure inside a structure in vb.net but i am confused as to assign values to the inner structure. I want to send the root structure (which contains the value of its own as well those of the inner structure) to another procedure. Someone please help. Thanks in advance
modified on Wednesday, May 27, 2009 6:07 AM
-
I am able to create a structure inside a structure in vb.net but i am confused as to assign values to the inner structure. I want to send the root structure (which contains the value of its own as well those of the inner structure) to another procedure. Someone please help. Thanks in advance
modified on Wednesday, May 27, 2009 6:07 AM
Something like this?
Public Structure InnerStruct
Public InnerTest As String
End Structure
Public Structure RootStruct
Public Test As String
Public myStruct As InnerStruct
End StructurePublic Class Form1
Public Sub ShowInnerText(ByVal whatStruct As RootStruct) MessageBox.Show(whatStruct.myStruct.InnerTest) End Sub Private Sub Button1\_Click(ByVal sender As System.Object, \_ ByVal e As System.EventArgs) Handles Button1.Click Dim newStruct As RootStruct newStruct.myStruct.InnerTest = "Hello world" ShowInnerText(newStruct) End Sub
End Class
I are troll :)
-
Something like this?
Public Structure InnerStruct
Public InnerTest As String
End Structure
Public Structure RootStruct
Public Test As String
Public myStruct As InnerStruct
End StructurePublic Class Form1
Public Sub ShowInnerText(ByVal whatStruct As RootStruct) MessageBox.Show(whatStruct.myStruct.InnerTest) End Sub Private Sub Button1\_Click(ByVal sender As System.Object, \_ ByVal e As System.EventArgs) Handles Button1.Click Dim newStruct As RootStruct newStruct.myStruct.InnerTest = "Hello world" ShowInnerText(newStruct) End Sub
End Class
I are troll :)
Expanding on Eddy's example:
Public Structure InnerStruct
Public InnerTest As StringPublic Sub Init InnerTest = "initialize your vars here" End Sub
End Structure
Public Structure RootStruct
Public Test As String
Public myStruct As InnerStruct
End StructureYou can have subs etc, within a struct. You can also have a CTOR; although it must have parameters. Just another option for you.
Any suggestions, ideas, or 'constructive criticism' are always welcome. "There's no such thing as a stupid question, only stupid people." - Mr. Garrison
-
Something like this?
Public Structure InnerStruct
Public InnerTest As String
End Structure
Public Structure RootStruct
Public Test As String
Public myStruct As InnerStruct
End StructurePublic Class Form1
Public Sub ShowInnerText(ByVal whatStruct As RootStruct) MessageBox.Show(whatStruct.myStruct.InnerTest) End Sub Private Sub Button1\_Click(ByVal sender As System.Object, \_ ByVal e As System.EventArgs) Handles Button1.Click Dim newStruct As RootStruct newStruct.myStruct.InnerTest = "Hello world" ShowInnerText(newStruct) End Sub
End Class
I are troll :)
-
Thank you very much for your help. Your code works fine. You have taught me how to do that. Previously I placed the InnerStruct inside the RootStructure and was groping around. Can it be done that way or was it a wrong approch ? Thank you once again.
You mean like this?
Public Structure RootStruct
Public Test As String
Public myStruct As InnerStructPublic Structure InnerStruct Public InnerTest As String End Structure
End Structure
That's valid too. Just don't forget to include a field that instantiates the struct in the RootStruct :)
I are troll :)
-
You mean like this?
Public Structure RootStruct
Public Test As String
Public myStruct As InnerStructPublic Structure InnerStruct Public InnerTest As String End Structure
End Structure
That's valid too. Just don't forget to include a field that instantiates the struct in the RootStruct :)
I are troll :)