Initializing structure arrays.

  • Thread starter Thread starter Steve
  • Start date Start date
S

Steve

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

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")}
 
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 "constructor" type subroutine
within the structure.

Thanks again

Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top