Thread: Problem

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Location
    UK
    Posts
    75
    Rep Power
    12

    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. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Apr 2002
    Posts
    693
    Rep Power
    26
    the prob is because the code continues after the msgbox. Quick and dirty is to just put an exit sub after the msgbox.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Location
    UK
    Posts
    75
    Rep Power
    12

    Hmmm


    Tried it, works. I was trying a loop but could not get the thing to work quite right.

    Thanks

    Charlie
  6. #4
  7. /(bb|[^b]{2})/

    Join Date
    Nov 2001
    Location
    Somewhere in the great unknown
    Posts
    5,163
    Rep Power
    792
    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.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Location
    UK
    Posts
    75
    Rep Power
    12

    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
  10. #6
  11. /(bb|[^b]{2})/

    Join Date
    Nov 2001
    Location
    Somewhere in the great unknown
    Posts
    5,163
    Rep Power
    792

IMN logo majestic logo threadwatch logo seochat tools logo