Results 1 to 4 of 4

Thread: [RESOLVED]Multi-Dimensional Array Get/Set Issue

  1. #1

    Thread Starter
    Hyperactive Member neef's Avatar
    Join Date
    Dec 2001
    Location
    Boston
    Posts
    311

    [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.
    Last edited by neef; Apr 20th, 2012 at 08:46 PM.
    Intermediate Level Programmer Extraordinaire

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: Multi-Dimensional Array Get/Set Issue

    something like this would work:

    vb Code:
    1. Public Class Form1
    2.     Private m_StoredRegSeasonGames(,) As List(Of CLStoredPlay)
    3.  
    4.     Friend ReadOnly Property StoredPreSeasonGames() As List(Of CLStoredPlay)(,)
    5.         Get
    6.             Return m_StoredRegSeasonGames
    7.         End Get
    8.         'Set(ByVal value(,) As List(Of CLStoredPlay))
    9.         '    m_StoredRegSeasonGames = value
    10.         'End Set
    11.     End Property
    12.  
    13.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    14.         Dim m_intNumberOfTeams As Integer = 12
    15.         ReDim m_StoredRegSeasonGames(17, m_intNumberOfTeams \ 2)
    16.         For y As Integer = 0 To m_StoredRegSeasonGames.GetUpperBound(0)
    17.             For x As Integer = 0 To m_StoredRegSeasonGames.GetUpperBound(1)
    18.                 m_StoredRegSeasonGames(y, x) = New List(Of CLStoredPlay)
    19.             Next
    20.         Next
    21.         StoredPreSeasonGames(0, 0).Add(New CLStoredPlay With {.a = 101, .b = "test"})
    22.     End Sub
    23.  
    24. End Class
    25.  
    26. Public Class CLStoredPlay
    27.     Public a As Integer
    28.     Public b As String
    29. End Class

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: Multi-Dimensional Array Get/Set Issue

    i forgot to mention, your property uses a different array than the declaration + redim you posted

  4. #4

    Thread Starter
    Hyperactive Member neef's Avatar
    Join Date
    Dec 2001
    Location
    Boston
    Posts
    311

    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.
    Intermediate Level Programmer Extraordinaire

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width