none
Help needed RRS feed

  • Question

  • Im creating an app that keeps track of goalie stats for hockey and I need help with creating an object or variable that saves a game along with the integers and doubles that come with it and attach it to a certain Goalie class. My guess is I need to create a new class that holds all the stats and have different objects for each game that holds those certain stats specified to that game however I am not sure how to do that. I want it to create one of those objects each time a game is ended via button. Ask if you need more info or clarification. Thank you.
    Monday, February 12, 2018 6:15 PM

All replies

  • Hi

    I have no real idea about Hockey at all - though I do believe it is about one team beating the hell out of the other.

    Here is some code to illustrate a very simple type ofthing which I think you are asking for.

    A series of Classes, each with it's own Properties. Someof the Properties are derived from the other Classes eg a Game has a List of Players (Player Class) and a Goalie (Goalie Class)

    The Properties are just random spurious items I thought up for this demo, but you can see how to plan your own data structures.

    You can also see how to create a new Game and add data tomcover all Properties.

    Option Strict On
    Option Explicit On
    Public Class Form1
      Dim Games As New List(Of Game)
      Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
    	' one game
    	Dim g As New Game
    	With g
    	  .Venue = "Hyde Park, London"
    	  .TeamList.AddRange({New Player With {.Name = "Les Hay", .GoalsScored = 21, .Position = "Centre Forward"}, New Player With {.Name = "Fred Bloggs", .GoalsScored = 12, .Position = "Left Back"}})
    	  .Goalie = New Goalie With {.Name = "Magnus Magnusson", .GoalsLetIn = 123, .SavesWorthAMention = 33, .FoulsGivenAway = 189, .Team = "Texas Wanderers"}
    	End With
    	Games.Add(g)
    
    	' second game
    	g = New Game
    	With g
    	  .Venue = "SuperBowl, USA"
    	  .TeamList.AddRange({New Player With {.Name = "Cor Himself", .GoalsScored = 345, .Position = "Right Back"}, New Player With {.Name = "Donald Trumph", .GoalsScored = 1, .Position = "Left Behind"}})
    	  .Goalie = New Goalie With {.Name = "Ford Prefect", .GoalsLetIn = 88, .SavesWorthAMention = 44, .FoulsGivenAway = 111, .Team = "Alabama Albanians"}
    	End With
    	Games.Add(g)
      End Sub
    End Class
    Class Game
      Property Venue As String
      Property TeamList As New List(Of Player)
      Property Goalie As Goalie
    End Class
    Class Goalie
      Property Name As String
      Property Team As String
      Property GoalsLetIn As Integer
      Property SavesWorthAMention As Integer
      Property FoulsGivenAway As Integer
    End Class
    Class Player
      Property Name As String
      Property Position As String
      Property GoalsScored As Integer
    End Class


    Regards Les, Livingston, Scotland

    Monday, February 12, 2018 8:27 PM
  • Im creating an app that keeps track of goalie stats for hockey and I need help with creating an object or variable that saves a game along with the integers and doubles that come with it and attach it to a certain Goalie class.

    Is the problem in defining the class to hold the values, in creating the class instance when the game is ended, in persisting that instance so that it can be accessed again in some further part of the gameplay or in attaching the instance to the goalie?   You should show the code (simplified if necessary) that you have so far to get to the point in that process where you are getting stuck.

    https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/objects-and-classes/

    Monday, February 12, 2018 8:28 PM
  • Hi Devun41,

    Your application sounds so interesting.
    When you add a new Class, do you insert a line of "Inherits <something>"?
    The below sample shows it.
    Public Class cls_Shipping
    	Inherits frm_Main    ' << -- this is what I said
    	' ---
    	Public Sub prc_Shipping()
    		' --- do something
    	End Sub
    End Class
    Regards,

    Ashidacchi

    Tuesday, February 13, 2018 1:57 AM