[RESOLVED]Multi-Dimensional Array Get/Set Issue
In my football sim I am trying to save all the info from a game. There are two defined dimensions to this array. The first is the number of weeks(17 always) and then the number of games per week (Number of teams /2). The plays themselves are unknown in quantity so I decided to use List of to store them.
With this type of multi-dimensional array that is also a List of I am having trouble with the Get and Set properties.
I have a member variable declared as:
Code:
Private m_StoredRegSeasonGames(,) As List(Of CLStoredPlay)
Later I redim the array:
Code:
ReDim m_StoredRegSeasonGames(17, m_intNumberOfTeams / 2)
My issue is I do not know the proper coding for the Get and Set Properties. This is the closest I could get:
Code:
Friend Property StoredPreSeasonGames As List(Of CLStoredPlay)(,)
Get
m_StoredPreSeasonGames = m_StoredPreSeasonGames
End Get
Set(ByVal value(,) As List(Of CLStoredPlay))
m_StoredPreSeasonGames = value
End Set
End Property
The only error I get with this version is a warning: StoredPreSeasonGames doesn't return a value on all code paths. Still, something is off. The parentheses and comma look wrongly placed. What am I missing?
Thanks in advance. :)
Re: Multi-Dimensional Array Get/Set Issue
something like this would work:
vb Code:
Public Class Form1
Private m_StoredRegSeasonGames(,) As List(Of CLStoredPlay)
Friend ReadOnly Property StoredPreSeasonGames() As List(Of CLStoredPlay)(,)
Get
Return m_StoredRegSeasonGames
End Get
'Set(ByVal value(,) As List(Of CLStoredPlay))
' m_StoredRegSeasonGames = value
'End Set
End Property
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim m_intNumberOfTeams As Integer = 12
ReDim m_StoredRegSeasonGames(17, m_intNumberOfTeams \ 2)
For y As Integer = 0 To m_StoredRegSeasonGames.GetUpperBound(0)
For x As Integer = 0 To m_StoredRegSeasonGames.GetUpperBound(1)
m_StoredRegSeasonGames(y, x) = New List(Of CLStoredPlay)
Next
Next
StoredPreSeasonGames(0, 0).Add(New CLStoredPlay With {.a = 101, .b = "test"})
End Sub
End Class
Public Class CLStoredPlay
Public a As Integer
Public b As String
End Class
Re: Multi-Dimensional Array Get/Set Issue
i forgot to mention, your property uses a different array than the declaration + redim you posted
Re: Multi-Dimensional Array Get/Set Issue
This was very helpful, thank you!
You were right that I cut and pasted my array incorrectly. I drank a Sam Adams right before I wrote this, so the lesson is don't drink and post.