
March 12th, 2003, 09:58 AM
|
|
Contributing User
|
|
Join Date: Feb 2003
Location: UK
Posts: 75
Time spent in forums: < 1 sec
Reputation Power: 11
|
|
|
Help with msgbox problem
Ive been having a problem with some code, I have been trying to prevent a user in a game of tic tac toe choosing a square that is already taken, I solved this part by using
Code:
If cmdNought(SquareNumber).Caption <> "" Then
MsgBox "Square already taken"
This solves my problem but ater displaying this box the prog gives out the message that the wrong player's turn is next, as if the prog thinks that the clicking on a square that was taken was an actual turn by a player, when it was an error.
So what i want to do is make the code realise that this was not a "Real" turn but an error and halt, producing the correct player number on the next click event.
here is my code, could someone help me make some sense of this please.
Code:
Option Explicit
Dim Player1 As Boolean
Dim Name1 As String
Dim Name2 As String
Private Sub cmdNought_Click(Index As Integer)
'Declare required storage
picOutput.Cls
Call PlaceSymbol(Index)
If Player1 Then
picOutput.Print "Player two to go "
Else
picOutput.Print "Player one to go "
End If
End Sub
Private Sub cmdPlay_Click()
'Declare required storage
Dim Name1 As String
Dim Name2 As String
Do
'Require user to input their name
Name1 = InputBox("Please enter your name ", "Enter Name")
Name1 = UCase(Left(Name1, 1)) & LCase(Right(Name1, Len(Name1) - 1))
'Output player one's name
Loop Until Name1 > ""
picOutput.Print "Player one is "; ""; (Name1)
Do
Name2 = InputBox("Please enter your name ", "Enter Name")
Name2 = UCase(Left(Name2, 1)) & LCase(Right(Name2, Len(Name2) - 1))
Loop Until Name2 > ""
'Output player two's name
picOutput.Cls
picOutput.Print "Player two is "; ""; (Name2)
picOutput.Print "Player one "; (Name1); " to go first "
End Sub
Private Sub cmdQuit_Click()
' Terminate Application
End
End Sub
Private Sub cmdSquare_Click(Index As Integer)
Call PlaceSymbol(Index)
End Sub
Private Sub PlaceSymbol(SquareNumber As Integer)
'carry out players actions
If cmdNought(SquareNumber).Caption <> "" Then
MsgBox "Square already taken"
End If
If Player1 Then
cmdNought(SquareNumber).Caption = "O"
Else
cmdNought(SquareNumber).Caption = "X"
End If
Player1 = Not Player1
End Sub
Thanks
Charlie
Last edited by Charlie : March 12th, 2003 at 01:52 PM.
|