(B is a checkbox that im keeping checked)VB Code:
Option Explicit Dim Player As Boolean Dim Space As Integer Dim Win As Boolean Dim Square(0 To 2) As String Dim Wins As New Collection Dim i As Integer Dim j As Integer Private Sub Form_Load() For i = 0 To 8 B(i).Caption = "" B(i).Value = vbChecked Next i With Wins .Add "012" .Add "345" .Add "678" .Add "036" .Add "147" .Add "258" .Add "048" .Add "246" End With End Sub Private Sub B_Click(Index As Integer) With B(Index) .Value = vbChecked If Win = False Then If .Caption = "" Then If Player = False Then .Caption = "X" Player = True ElseIf Player = True Then .Caption = "O" Player = False End If End If For j = 1 To 8 For i = 1 To 3 [B]Square(i - 1) = Mid(Wins(j), i, 1)[/B] Next i If B(Square(0)) = "X" And B(Square(1)) = "X" And B(Square(2)) = "X" Then Win = True MsgBox "Player X Won" Exit For ElseIf B(Square(0)) = "O" And B(Square(1)) = "O" And B(Square(2)) = "O" Then Win = True MsgBox "Player O Won" Exit For End If Next j For i = 0 To 8 If B(i).Caption = "" Then Space = Space + 1 End If Next i If Space = 0 Then Win = True MsgBox "Tie" End If End If End With End Sub
This is a tic-tac-toe game, and instead of checked all the checkboxs to see if someone won, I decided to use a collection and parse out each integer and check that way. I keep getting a error on the bolded line though and im not sure why. The line looks fine for me and should produce the results Square(0) = 0, Square(1) = 1, and Square(2) = 2. Could anybody help me with this?




Reply With Quote