Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Structure within structure - Help needed [modified]

Structure within structure - Help needed [modified]

Scheduled Pinned Locked Moved Visual Basic
csharphelp
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tiagu
    wrote on last edited by
    #1

    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

    L 1 Reply Last reply
    0
    • T tiagu

      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

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Something like this?

      Public Structure InnerStruct
      Public InnerTest As String
      End Structure
      Public Structure RootStruct
      Public Test As String
      Public myStruct As InnerStruct
      End Structure

      Public 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 :)

      J T 2 Replies Last reply
      0
      • L Lost User

        Something like this?

        Public Structure InnerStruct
        Public InnerTest As String
        End Structure
        Public Structure RootStruct
        Public Test As String
        Public myStruct As InnerStruct
        End Structure

        Public 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 :)

        J Offline
        J Offline
        Jon_Boy
        wrote on last edited by
        #3

        Expanding on Eddy's example:

        Public Structure InnerStruct
        Public InnerTest As String

        Public Sub Init
            InnerTest = "initialize your vars here"
        End Sub
        

        End Structure
        Public Structure RootStruct
        Public Test As String
        Public myStruct As InnerStruct
        End Structure

        You 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

        1 Reply Last reply
        0
        • L Lost User

          Something like this?

          Public Structure InnerStruct
          Public InnerTest As String
          End Structure
          Public Structure RootStruct
          Public Test As String
          Public myStruct As InnerStruct
          End Structure

          Public 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 :)

          T Offline
          T Offline
          tiagu
          wrote on last edited by
          #4

          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.

          L 1 Reply Last reply
          0
          • T tiagu

            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.

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            You mean like this?

            Public Structure RootStruct
            Public Test As String
            Public myStruct As InnerStruct

            Public 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 :)

            T 1 Reply Last reply
            0
            • L Lost User

              You mean like this?

              Public Structure RootStruct
              Public Test As String
              Public myStruct As InnerStruct

              Public 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 :)

              T Offline
              T Offline
              tiagu
              wrote on last edited by
              #6

              Okay, i got it.   Thank you very much for your time and help.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups