mahmed1
Well-known Member
- Joined
- Mar 28, 2009
- Messages
- 2,302
- Office Version
- 365
- 2016
- Platform
- Windows
Hi
I am trying to set up a class that has a Team name, Player Name and Players (Collection to add players) but i am getting an error saying variable not set. Please advise if im on the right track and give some pointers to where i can improve
Thank You
P.s how would i encorporate into the NEW class multiple names from the sheet1 Range A2:A10 where it hold the player names
Do i need to create an instance for each player name in the loop or can i leave it as 1 instance?
i.e
I have set up these 3 classes.
Team clas has 2 properties - Name and Player (class) to access Player Class
Normal Module
Team Class module
Player Class module
Players Class Module (Collection)
I am trying to set up a class that has a Team name, Player Name and Players (Collection to add players) but i am getting an error saying variable not set. Please advise if im on the right track and give some pointers to where i can improve
Thank You
P.s how would i encorporate into the NEW class multiple names from the sheet1 Range A2:A10 where it hold the player names
Do i need to create an instance for each player name in the loop or can i leave it as 1 instance?
i.e
Code:
For i = 2 to 10
Set AddPlayer = New PlayersTeam.Player.Name = Sheets("Sheet1").Range("A" & i).value
Players.Add Player, Team.Player.Name
Set Players = Nothing
Next i
I have set up these 3 classes.
Team clas has 2 properties - Name and Player (class) to access Player Class
Normal Module
Code:
Sub test()
Dim Team As Team
Dim Player As Player
Dim Players As Players
Set Team = New Team
Set Player = New Player
Set Players= New Players
Team.Player.Name = "Joe Bloggs"
Players.Add Player, Team.Player.Name
End Sub
Team Class module
Code:
Private pName As String
Private pPlayer As Player
Public Property Let Name(value As String)
pName = value
End Property
Public Property Get Name() As String
Name = pName
End Property
Public Property Let Player(value As Player)
Set pPlayer = value
End Property
Public Property Get Player() As Player
Set Player = pPlayer
End Property
Player Class module
Code:
Private pName As String
Public Property Let Name(value As String)
pName = value
End Property
Public Property Get Name() As String
Name = pName
End Property
Players Class Module (Collection)
Code:
Private pAddPlayers As Collection
Private Sub Class_Initialize()
Set pAddPlayers = New Collection
End Sub
Sub Add(Item As Player, Key As String)
pAddPlayers.Add Item, Key
End Sub
Public Property Get Count() As Long
Count = pAddPlayers.Count
End Property
Public Property Get Item(NameORnumber As Variant) As Player
Set Item = pAddPlayers.Item(NameORnumber)
End Property