Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 12th, 2003, 09:58 AM
Charlie Charlie is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: UK
Posts: 75 Charlie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #2  
Old March 12th, 2003, 01:26 PM
hedge hedge is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2002
Posts: 693 hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 5 Days 4 h 5 m 20 sec
Reputation Power: 25
the prob is because the code continues after the msgbox. Quick and dirty is to just put an exit sub after the msgbox.

Reply With Quote
  #3  
Old March 12th, 2003, 01:33 PM
Charlie Charlie is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: UK
Posts: 75 Charlie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 11
Hmmm

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

Thanks

Charlie

Reply With Quote
  #4  
Old March 12th, 2003, 01:42 PM
Onslaught's Avatar
Onslaught Onslaught is offline
/(bb|[^b]{2})/
Dev Shed God (5000 - 5499 posts)
 
Join Date: Nov 2001
Location: Somewhere in the great unknown
Posts: 5,163 Onslaught User rank is Major General (70000 - 90000 Reputation Level)Onslaught User rank is Major General (70000 - 90000 Reputation Level)Onslaught User rank is Major General (70000 - 90000 Reputation Level)Onslaught User rank is Major General (70000 - 90000 Reputation Level)Onslaught User rank is Major General (70000 - 90000 Reputation Level)Onslaught User rank is Major General (70000 - 90000 Reputation Level)Onslaught User rank is Major General (70000 - 90000 Reputation Level)Onslaught User rank is Major General (70000 - 90000 Reputation Level)Onslaught User rank is Major General (70000 - 90000 Reputation Level)Onslaught User rank is Major General (70000 - 90000 Reputation Level)Onslaught User rank is Major General (70000 - 90000 Reputation Level)Onslaught User rank is Major General (70000 - 90000 Reputation Level)Onslaught User rank is Major General (70000 - 90000 Reputation Level)Onslaught User rank is Major General (70000 - 90000 Reputation Level) 
Time spent in forums: 6 Days 1 h 34 m 20 sec
Reputation Power: 791
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.

Reply With Quote
  #5  
Old March 12th, 2003, 01:48 PM
Charlie Charlie is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: UK
Posts: 75 Charlie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 11
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

Reply With Quote
  #6  
Old March 12th, 2003, 02:14 PM
Onslaught's Avatar
Onslaught Onslaught is offline
/(bb|[^b]{2})/
Dev Shed God (5000 - 5499 posts)
 
Join Date: Nov 2001
Location: Somewhere in the great unknown
Posts: 5,163 Onslaught User rank is Major General (70000 - 90000 Reputation Level)Onslaught User rank is Major General (70000 - 90000 Reputation Level)Onslaught User rank is Major General (70000 - 90000 Reputation Level)Onslaught User rank is Major General (70000 - 90000 Reputation Level)Onslaught User rank is Major General (70000 - 90000 Reputation Level)Onslaught User rank is Major General (70000 - 90000 Reputation Level)Onslaught User rank is Major General (70000 - 90000 Reputation Level)Onslaught User rank is Major General (70000 - 90000 Reputation Level)Onslaught User rank is Major General (70000 - 90000 Reputation Level)Onslaught User rank is Major General (70000 - 90000 Reputation Level)Onslaught User rank is Major General (70000 - 90000 Reputation Level)Onslaught User rank is Major General (70000 - 90000 Reputation Level)Onslaught User rank is Major General (70000 - 90000 Reputation Level)Onslaught User rank is Major General (70000 - 90000 Reputation Level) 
Time spent in forums: 6 Days 1 h 34 m 20 sec
Reputation Power: 791
Not a problem.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > Problem

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap