check for a draw

wont add score to label control

Page 1 of 1

2 Replies - 779 Views - Last Post: 12 May 2010 - 11:15 AM Rate Topic: -----

#1 John-Ellis   User is offline

  • D.I.C Regular

Reputation: 8
  • View blog
  • Posts: 305
  • Joined: 23-March 10

check for a draw

Posted 12 May 2010 - 05:31 AM

Hi All,

I dont quite understand why this wont work i was hoping someone could help, I have got a noughts and crosses game and its all finished appart from the checkdraw sub routine i forgott to write in, so I wrote it out as below:

Private Sub CheckDraw()

If btn2.Text.Length = 1 and so on until btn10 Then
ScoreX += 1
ScoreO += 1
MessageBox.Show("Draw")
End If
End Sub

Now ScoreX and ScoreO are two variables declaired at form level, I use a very simaler routine for CheckWin and that works a treat.

My problem is that when a draw is detected the message box comes up ok but no scores are added to the label control.


Can anyone see anything im missing.

Thanks very much

John

Is This A Good Question/Topic? 0
  • +

Replies To: check for a draw

#2 _HAWK_   User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1162
  • View blog
  • Posts: 4,444
  • Joined: 02-July 08

Re: check for a draw

Posted 12 May 2010 - 07:31 AM

For some simplicity how about a loop:

For index As Integer = 2 To 10 
   If Me.Controls("btn" & index.ToString).Text.Length = 1 Then
      ScoreX += 1
      ScoreO += 1
      'add the score to the labels - you'll have to use your label names
      labelX.Text = ScoreX.ToString
      labelO.Text = ScoreO.ToString
   End If
Next

Was This Post Helpful? 0
  • +
  • -

#3 John-Ellis   User is offline

  • D.I.C Regular

Reputation: 8
  • View blog
  • Posts: 305
  • Joined: 23-March 10

Re: check for a draw

Posted 12 May 2010 - 11:15 AM

View Posthawkvalley1, on 12 May 2010 - 06:31 AM, said:

For some simplicity how about a loop:

For index As Integer = 2 To 10 
   If Me.Controls("btn" & index.ToString).Text.Length = 1 Then
      ScoreX += 1
      ScoreO += 1
      'add the score to the labels - you'll have to use your label names
      labelX.Text = ScoreX.ToString
      labelO.Text = ScoreO.ToString
   End If
Next


Thanks for that one mate, reading your reply I realised that I didnt update the label text.

Works a treat now.

Thanks again

John
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1