Hi,

I have started my new college course this week and received my first assignment, it is to create a simple noughts and crosses game.

So far all is well, I have created all of my procedures for checking for winners, reseting the game board and so on, the only issue I have is the button click events don't do anything when I click one of the nine buttons to put in either an X or O.

Please see below my code for the button click event (FYI I have changed all the font and colour properties for each button in the properties tab in VS).

 Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

        If cboUser.Text = "X" Then
            Panel1.Enabled = True
            btn1.Text = "X"
        Else
            cboUser.Text = "O"
            Panel1.Enabled = True
            btn1.Text = "O"
        End If

        Call CheckWinner()

    End Sub

So to quickly explain what this is supposed to do, when a new game is started the user selects either a X or O from a combo box (cboUser) this action enables the panel control so the user can then insert either the X or O into a button in this case button 1, when the user selects the button the program checks to see if anyone has won. I have the same code for all 9 buttons but as I say nothing happens when I click any of the buttons.

I know there is loads of noughts and crosses games I can download and use other peoples code but that's just cheeting.

Can anyone help. If you need any code for the rest of the program please let me know.

Cheers

one thing I have realised I didnt need is the 4th line panel1.enabled = true, I already have this action in the cboUser text changed event.

UPDATE...

I have taken the button controls out of the panel and deleted the panel control, re coded the buttons for there enabling and disabling, moved the form load and button click events to the top and moved the procedures to the bottom but still no action on the button click event????

It must be the code I am using for the btn click event, it must be wrong.

You are missing the handles part. So far you've declared a sub and give it some actions to perform, but it wouldn't make a difference if you've called it "abcd". The handles part of the declaration is what ties it to an event and make the event run that sub.
Change Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
to Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) handles btn1.Click

Edited 3 Years Ago by adam_k

well chuff me, I thought VB put that code in automatically when I double click the button control so I never even thought to check it.

Thanks very much adam_k

Visual studio does put it in automatically, but things happen and it might get deleted.
When you've got an event not running the sub it's supposed to, thats the one place you start.
If this has solved your problem, please mark this as solved.
Thanks.

This article has been dead for over six months. Start a new discussion instead.