I have been getting into some object-oriented features of VB6. I've done lots of OOP with Java, and I'm trying to get this to work:
I have a array of Card objects, I want to check if an object in the index in the array has been created.
Dim cardsPlayer1(1 To 10) As Card
I created objects like this:
Set cardsPlayer1(index) = New Card
If tried using this to test if I have assigned an object to an index yet:
For counter = 1 To 10
If (cardsPlayer1(counter) Is Nothing) Then
Set cardsPlayer1(counter) = New Card
End If
Next counter
But it gave me a true value everytime and creating a new object to the whole array.
Here's the relevant code:
'Jordan Mathewson
'May 31, 2013
Dim cardsPlayer1(1 To 10) As Card
Dim cardsPlayer2(1 To 10) As Card
Private Sub cmdStartGame_Click()
Call addCard(1)
End Sub
'Called to add a card to one of the player's stacks
Private Sub addCard(player As Integer)
Dim counter As Integer
'To add a card to player1..
If (player = 1) Then
For counter = 1 To 10
If (cardsPlayer1(counter) Is Nothing) Then
Print "Object created." '<- Printed 10 times.
Set cardsPlayer1(counter) = New Card
End If
Next counter
'To add a card to player2..
Else
For counter = 1 To 10
If (cardsPlayer2(counter) Is Nothing) Then
Set cardsPlayer2(counter) = New Card
End If
Next counter
End If
Call refreshForm
End Sub