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

Dani AI

Generated

Quick summary: the draw detection was firing (the MessageBox appeared) but the on‑form labels did not change because their text was never updated in the UI. correctly pointed that out and confirmed the immediate fix worked.

Common causes and quick checks

  1. Variable scope — confirm ScoreX/ScoreO are declared at form/class level and not accidentally Dimed again inside the routine (local shadowing).
  2. Control identity — make sure the code updates the actual Label controls on the form (no typos in the control names).
  3. UI update timing — update the label text before showing a modal dialog; updating after can make the change invisible until later. If the app uses background threads, marshal updates to the UI thread.
  4. Type/format — numeric values should be converted to strings for display (explicit conversion avoids surprises and lets you control formatting).

Better draw detection and maintenance

  • Checking Text.Length = 1 for each button is brittle. Prefer String.IsNullOrWhiteSpace or test for nonempty text, and loop the button collection (or use LINQ) instead of spelling out every button.
  • Keep score UI updates in one small method (eg. UpdateScoreLabels) and call it wherever scores change — reduces duplication and mistakes.
  • Consider tracking draws with a separate counter rather than incrementing both players’ scores; it makes results and statistics clearer.

References: the Label Text property and the String.IsNullOrWhiteSpace helper are useful to review: Label.Text docs and String.IsNullOrWhiteSpace docs.

Recommended Answers

All 2 Replies

Because you are not changing the Text of the label controls.

Try something like:

ScoreX += 1
ScoreO += 1

scoreXLabel.Text = ScoreX
scoreYLabel.Text = ScoreY

Thanks

Nice one, thanks for that farooqa, works a treat.

Thanks again mate.

John

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.