Note that there are some explanatory texts on larger screens.

plurals
  1. POKeep track of wins in my tic tac toe application VB 2010
    primarykey
    data
    text
    <p>I've written a Tic Tac Toe application in VB 2010 and it runs well, but I'd like to be able to keep track of the number of wins for X's and O's and/or Player 1 and Player 2. I've tried adding in do while loops, but I'm pretty ignorant as to how to correctly implement them and I'm unsure if that's even the correct way to track wins.. Any help would be greatly appreciated! Here's my code:</p> <p>Public Class Form1</p> <pre><code>Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Private Sub btn11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn11.Click 'clos the form Me.Close() End Sub Private Sub btn10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn10.Click btn1.Enabled = True btn2.Enabled = True btn3.Enabled = True btn4.Enabled = True btn5.Enabled = True btn6.Enabled = True btn7.Enabled = True btn8.Enabled = True btn9.Enabled = True btn1.Text = "" btn2.Text = "" btn3.Text = "" btn4.Text = "" btn5.Text = "" btn6.Text = "" btn7.Text = "" btn8.Text = "" btn9.Text = "" End Sub Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click If lbl2.Text = "X" Then btn1.Text = "X" lbl2.Text = "O" Else btn1.Text = "O" lbl2.Text = "X" End If btn1.Enabled = False End Sub Private Sub btn2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn2.Click If lbl2.Text = "X" Then btn2.Text = "X" lbl2.Text = "O" Else btn2.Text = "O" lbl2.Text = "X" End If Call win() btn2.Enabled = False End Sub Private Sub btn3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn3.Click If lbl2.Text = "X" Then btn3.Text = "X" lbl2.Text = "O" Else btn3.Text = "O" lbl2.Text = "X" End If Call win() btn3.Enabled = False End Sub Private Sub btn4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn4.Click If lbl2.Text = "X" Then btn4.Text = "X" lbl2.Text = "O" Else btn4.Text = "O" lbl2.Text = "X" End If Call win() btn4.Enabled = False End Sub Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn5.Click If lbl2.Text = "X" Then btn5.Text = "X" lbl2.Text = "O" Else btn5.Text = "O" lbl2.Text = "X" End If Call win() btn5.Enabled = False End Sub Private Sub btn6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn6.Click If lbl2.Text = "X" Then btn6.Text = "X" lbl2.Text = "O" Else btn6.Text = "O" lbl2.Text = "X" End If Call win() btn6.Enabled = False End Sub Private Sub btn7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn7.Click If lbl2.Text = "X" Then btn7.Text = "X" lbl2.Text = "O" Else btn7.Text = "O" lbl2.Text = "X" End If Call win() btn7.Enabled = False End Sub Private Sub btn8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn8.Click If lbl2.Text = "X" Then btn8.Text = "X" lbl2.Text = "O" Else btn8.Text = "O" lbl2.Text = "X" End If Call win() btn8.Enabled = False End Sub Private Sub btn9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn9.Click If lbl2.Text = "X" Then btn9.Text = "X" lbl2.Text = "O" Else btn9.Text = "O" lbl2.Text = "X" End If Call win() btn9.Enabled = False End Sub Private Sub win() If btn1.Text = "X" And btn2.Text = "X" And btn3.Text = "X" Then lbl2.Text = "X wins" btn1.Enabled = False btn2.Enabled = False btn3.Enabled = False btn4.Enabled = False btn5.Enabled = False btn6.Enabled = False btn7.Enabled = False btn8.Enabled = False btn9.Enabled = False End If If btn4.Text = "X" And btn5.Text = "X" And btn6.Text = "X" Then lbl2.Text = "X wins" btn1.Enabled = False btn2.Enabled = False btn3.Enabled = False btn4.Enabled = False btn5.Enabled = False btn6.Enabled = False btn7.Enabled = False btn8.Enabled = False btn9.Enabled = False End If If btn7.Text = "X" And btn8.Text = "X" And btn9.Text = "X" Then lbl2.Text = "X wins" btn1.Enabled = False btn2.Enabled = False btn3.Enabled = False btn4.Enabled = False btn5.Enabled = False btn6.Enabled = False btn7.Enabled = False btn8.Enabled = False btn9.Enabled = False End If If btn1.Text = "X" And btn4.Text = "X" And btn7.Text = "X" Then lbl2.Text = "X wins" btn1.Enabled = False btn2.Enabled = False btn3.Enabled = False btn4.Enabled = False btn5.Enabled = False btn6.Enabled = False btn7.Enabled = False btn8.Enabled = False btn9.Enabled = False End If If btn2.Text = "X" And btn5.Text = "X" And btn8.Text = "X" Then lbl2.Text = "X wins" btn1.Enabled = False btn2.Enabled = False btn3.Enabled = False btn4.Enabled = False btn5.Enabled = False btn6.Enabled = False btn7.Enabled = False btn8.Enabled = False btn9.Enabled = False End If If btn3.Text = "X" And btn6.Text = "X" And btn9.Text = "X" Then lbl2.Text = "X wins" btn1.Enabled = False btn2.Enabled = False btn3.Enabled = False btn4.Enabled = False btn5.Enabled = False btn6.Enabled = False btn7.Enabled = False btn8.Enabled = False btn9.Enabled = False End If If btn1.Text = "X" And btn5.Text = "X" And btn9.Text = "X" Then lbl2.Text = "X wins" btn1.Enabled = False btn2.Enabled = False btn3.Enabled = False btn4.Enabled = False btn5.Enabled = False btn6.Enabled = False btn7.Enabled = False btn8.Enabled = False btn9.Enabled = False End If If btn3.Text = "X" And btn5.Text = "X" And btn7.Text = "X" Then lbl2.Text = "X wins" btn1.Enabled = False btn2.Enabled = False btn3.Enabled = False btn4.Enabled = False btn5.Enabled = False btn6.Enabled = False btn7.Enabled = False btn8.Enabled = False btn9.Enabled = False End If If btn1.Text = "O" And btn2.Text = "O" And btn3.Text = "O" Then lbl2.Text = "O wins" btn1.Enabled = False btn2.Enabled = False btn3.Enabled = False btn4.Enabled = False btn5.Enabled = False btn6.Enabled = False btn7.Enabled = False btn8.Enabled = False btn9.Enabled = False End If If btn4.Text = "O" And btn5.Text = "O" And btn6.Text = "O" Then lbl2.Text = "O wins" btn1.Enabled = False btn2.Enabled = False btn3.Enabled = False btn4.Enabled = False btn5.Enabled = False btn6.Enabled = False btn7.Enabled = False btn8.Enabled = False btn9.Enabled = False End If If btn7.Text = "O" And btn8.Text = "O" And btn9.Text = "O" Then lbl2.Text = "O wins" btn1.Enabled = False btn2.Enabled = False btn3.Enabled = False btn4.Enabled = False btn5.Enabled = False btn6.Enabled = False btn7.Enabled = False btn8.Enabled = False btn9.Enabled = False End If If btn1.Text = "O" And btn4.Text = "O" And btn7.Text = "O" Then lbl2.Text = "O wins" btn1.Enabled = False btn2.Enabled = False btn3.Enabled = False btn4.Enabled = False btn5.Enabled = False btn6.Enabled = False btn7.Enabled = False btn8.Enabled = False btn9.Enabled = False End If If btn2.Text = "O" And btn5.Text = "O" And btn8.Text = "O" Then lbl2.Text = "O wins" btn1.Enabled = False btn2.Enabled = False btn3.Enabled = False btn4.Enabled = False btn5.Enabled = False btn6.Enabled = False btn7.Enabled = False btn8.Enabled = False btn9.Enabled = False End If If btn3.Text = "O" And btn6.Text = "O" And btn9.Text = "O" Then lbl2.Text = "O wins" btn1.Enabled = False btn2.Enabled = False btn3.Enabled = False btn4.Enabled = False btn5.Enabled = False btn6.Enabled = False btn7.Enabled = False btn8.Enabled = False btn9.Enabled = False End If If btn1.Text = "O" And btn5.Text = "O" And btn9.Text = "O" Then lbl2.Text = "O wins" btn1.Enabled = False btn2.Enabled = False btn3.Enabled = False btn4.Enabled = False btn5.Enabled = False btn6.Enabled = False btn7.Enabled = False btn8.Enabled = False btn9.Enabled = False End If If btn3.Text = "O" And btn5.Text = "O" And btn7.Text = "O" Then lbl2.Text = "O wins" btn1.Enabled = False btn2.Enabled = False btn3.Enabled = False btn4.Enabled = False btn5.Enabled = False btn6.Enabled = False btn7.Enabled = False btn8.Enabled = False btn9.Enabled = False End If End Sub </code></pre> <p>End Class</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload