Initializing structure arrays.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steve

    #1

    Initializing structure arrays.

    I have defined a structure of;

    Private Structure Menu
    Private MenuID as string
    Private Label as string
    End Structure

    ....and I would like to create and initialize an array of type "Menu". I have
    tried numerous variations on the theme;

    Public arrMenu as Menu = {{"a","b"},{"c" ,"d"},{"e","f"} }

    ....but all to no avail. Is this possible? If so how?

    Thanks

    Steve


  • Tom Shelton

    #2
    Re: Initializing structure arrays.

    In article <uabc8qKuFHA.40 32@TK2MSFTNGP15 .phx.gbl>, Steve wrote:[color=blue]
    > I have defined a structure of;
    >
    > Private Structure Menu
    > Private MenuID as string
    > Private Label as string
    > End Structure
    >
    > ...and I would like to create and initialize an array of type "Menu". I have
    > tried numerous variations on the theme;
    >
    > Public arrMenu as Menu = {{"a","b"},{"c" ,"d"},{"e","f"} }
    >
    > ...but all to no avail. Is this possible? If so how?
    >
    > Thanks
    >
    > Steve
    >
    >[/color]

    Private Structure Menu
    Public Sub New (ByVal MenuID As String, ByVal Label As String)
    Me.MenuID = MenuID
    Me.Label = Label
    End Sub

    Public MenuID As String
    Public Label As String
    End Structure

    Public arrMenu () As Menu = _
    {New Menu ("a", "b"), New Menu ("c", "d"), New Menu ("e", "f")}

    --
    Tom Shelton [MVP]

    Comment

    • Steve

      #3
      Re: Initializing structure arrays.

      Hi Tom, thanks for your swift response.

      I think I see what's happening. The "New" sub within the "Menu" structure
      gets called for each invocation of the "new Menu" request, and the code
      assigns the variables to it's own structure by use of the "me" keyword.

      I knew there had to be a way to do this but I couldn't make the leap of
      imagination needed to see that it involved a "constructo r" type subroutine
      within the structure.

      Thanks again

      Steve

      "Tom Shelton" <tom@YOUKNOWTHE DRILLmtogden.co m> wrote in message
      news:OdaI3HLuFH A.3188@TK2MSFTN GP14.phx.gbl...[color=blue]
      > In article <uabc8qKuFHA.40 32@TK2MSFTNGP15 .phx.gbl>, Steve wrote:[color=green]
      >> I have defined a structure of;
      >>
      >> Private Structure Menu
      >> Private MenuID as string
      >> Private Label as string
      >> End Structure
      >>
      >> ...and I would like to create and initialize an array of type "Menu". I
      >> have
      >> tried numerous variations on the theme;
      >>
      >> Public arrMenu as Menu = {{"a","b"},{"c" ,"d"},{"e","f"} }
      >>
      >> ...but all to no avail. Is this possible? If so how?
      >>
      >> Thanks
      >>
      >> Steve
      >>
      >>[/color]
      >
      > Private Structure Menu
      > Public Sub New (ByVal MenuID As String, ByVal Label As String)
      > Me.MenuID = MenuID
      > Me.Label = Label
      > End Sub
      >
      > Public MenuID As String
      > Public Label As String
      > End Structure
      >
      > Public arrMenu () As Menu = _
      > {New Menu ("a", "b"), New Menu ("c", "d"), New Menu ("e", "f")}
      >
      > --
      > Tom Shelton [MVP][/color]


      Comment

      Working...