|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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. |
|
#2
|
|||
|
|||
|
the prob is because the code continues after the msgbox. Quick and dirty is to just put an exit sub after the msgbox.
|
|
#3
|
|||
|
|||
|
Hmmm
Tried it, works. I was trying a loop but could not get the thing to work quite right.
Thanks Charlie |
|
#4
|
||||
|
||||
|
In the future please try to have a more descriptive subject title.
Following the link in the sticky at the top of this forum can give you some good information on how to do this. |
|
#5
|
|||
|
|||
|
Sorry
I have edited the title, I gotta admit my mind was elsewhere at the time.
Looks dumb to me now but I suppose these things happen. Charlie |
|
#6
|
||||
|
||||
|
Not a problem.
![]() |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > Problem |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|