Array of Undefined size - Declaration in Structure causes pass over/hang?
Hello again!
I'm having a problem whilst attempting to create a small database of sorts.
When trying:
Code:
Public Class Form1
Structure Items
Dim Food As String
Dim Extras() As String
Dim Price As Double
End Structure
Dim Food(6) As Items
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Food(0).Food = "Burger"
Food(1).Food = "Chkn Burger"
Food(2).Food = "Sausage"
Food(3).Food = "Nuggets!!!!"
Food(4).Food = "CornDog"
Food(5).Food = "Fries"
Food(6).Food = "Onion Rings"
' ''Burger
Label1.Text = "One"
Food(0).Extras(0) = "Cheese"
Food(0).Extras(1) = "Bacon"
Food(0).Extras(2) = "Extra Onions"
''Chkn Burg.
Label1.Text = "Two"
Food(1).Extras(0) = "Cheese"
Food(1).Extras(1) = "Xtra Sauce"
'' Sausage
Food(2).Extras(0) = "Cheese"
Food(2).Extras(1) = "Chilli"
'Nuggets
Food(3).Extras(0) = "Plum"
Food(3).Extras(1) = "Sweet & Sour"
Food(0).Price = 1.25
Food(1).Price = 1.75
Food(2).Price = 2.0
Food(3).Price = 2.0
For X = 0 To Food.Length
cbItemChoose.Items.Add(Food(X).Food)
Next
End Sub
It runs the program without error, but the "cbItemChoose" Dropdown does't get populated. I put the lines to change the "Label1" as a test, at which it gets to "One" but never "two".
If I comment out every line that has the Food(x).Extras(y) in it, the program populates the dropdown, but runs into an error as expected when trying to use the extras.
I'm not sure if there's another way to declare this, or if it's just another error on my fault of HOW I'm declaring this.
You'll notice, should you choose to look at the attachment, that I have a lot of variables at the top. The point of this structure is to make rid of all this messy declaration, as I am striving for efficiency.