Hi guys

I am trying to declare a array within a structure, and it is not working. I'll paste the code below and if anyone can help it would be greatly appreciated.

Structure league
Dim id As String
Dim name As String
Dim players(20) As String
End Structure

Dim leagues(100) As league

So I want each league to have a single name and id and 20 players.
Is there a way other than writing out dim player1, player2 etc.

Try

Structure league
    Dim id As String
    Dim name As String
    Dim players() As String
End Structure

Dim leagues(100) As league
for i as integer = 0 to 100
    redim leagues(i).players(20)
next

I don't know why there should be a restriction on declaring the length of the players array when the struct is defined but apparently there is. An alternative would be to use a class instead of a struct as

Public Class League

    Public id As String
    Public name As String
    Public players(20) As String

End Class

I should also point out that if you use a Class you will have to create each element of leagues with "New" as in

Public Class League
    Public id As String
    Public name As String
    Public players(20) As String
End Class
.
.
.
Dim leagues(20) As League

For i As Integer = 0 To UBound(leagues)
    leagues(i) = New League
Next

Doesn't seem to work, although you gave me some inspiration and I have solved the matter with a 3D array. Thanks :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.