Results 1 to 8 of 8

Thread: Cant use mid function on collection

Threaded View

  1. #1

    Thread Starter
    Addicted Member Piller's Avatar
    Join Date
    Oct 2004
    Location
    california
    Posts
    177

    Resolved Cant use mid function on collection

    VB Code:
    1. Option Explicit
    2. Dim Player As Boolean
    3. Dim Space As Integer
    4. Dim Win As Boolean
    5. Dim Square(0 To 2) As String
    6. Dim Wins As New Collection
    7. Dim i As Integer
    8. Dim j As Integer
    9.  
    10. Private Sub Form_Load()
    11. For i = 0 To 8
    12.     B(i).Caption = ""
    13.     B(i).Value = vbChecked
    14. Next i
    15. With Wins
    16.     .Add "012"
    17.     .Add "345"
    18.     .Add "678"
    19.     .Add "036"
    20.     .Add "147"
    21.     .Add "258"
    22.     .Add "048"
    23.     .Add "246"
    24. End With
    25. End Sub
    26.  
    27. Private Sub B_Click(Index As Integer)
    28. With B(Index)
    29. .Value = vbChecked
    30.     If Win = False Then
    31.         If .Caption = "" Then
    32.             If Player = False Then
    33.                 .Caption = "X"
    34.                 Player = True
    35.             ElseIf Player = True Then
    36.                 .Caption = "O"
    37.                 Player = False
    38.             End If
    39.         End If
    40.        
    41.         For j = 1 To 8
    42.             For i = 1 To 3
    43.                 [B]Square(i - 1) = Mid(Wins(j), i, 1)[/B]
    44.             Next i
    45.            
    46.             If B(Square(0)) = "X" And B(Square(1)) = "X" And B(Square(2)) = "X" Then
    47.                 Win = True
    48.                 MsgBox "Player X Won"
    49.                 Exit For
    50.             ElseIf B(Square(0)) = "O" And B(Square(1)) = "O" And B(Square(2)) = "O" Then
    51.                 Win = True
    52.                 MsgBox "Player O Won"
    53.                 Exit For
    54.             End If
    55.         Next j
    56.        
    57.         For i = 0 To 8
    58.             If B(i).Caption = "" Then
    59.                 Space = Space + 1
    60.             End If
    61.         Next i
    62.        
    63.         If Space = 0 Then
    64.             Win = True
    65.             MsgBox "Tie"
    66.         End If
    67.     End If
    68. End With
    69. End Sub
    (B is a checkbox that im keeping checked)
    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?
    Last edited by Piller; May 6th, 2006 at 02:38 PM.
    Are we alive or just breathing?

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