Help with code
-
I am working on a program for tic tac toe. The program is using text boxes with click event so when the box is clicked it will populate with a X or O unless it is already populated. I have everything working except my subrotine which is called from the checkfor win to check for a tie. Here is the code I am trying to use to check for a tie. Can someone please help me with why this causes the program to crash and also how to fix this code. Sub checkfortie() If txtPosition1.Text <> "" And txtPosition2.Text <> "" & txtPosition3.Text <> "" And _ txtPosition4.Text <> "" And txtPosition5.Text <> "" And txtPosition6.Text <> "" _ And txtPosition7.Text <> "" And txtPosition8.Text <> "" And txtPosition9.Text <> "" Then Catwins += 1 End If End Sub
-
I am working on a program for tic tac toe. The program is using text boxes with click event so when the box is clicked it will populate with a X or O unless it is already populated. I have everything working except my subrotine which is called from the checkfor win to check for a tie. Here is the code I am trying to use to check for a tie. Can someone please help me with why this causes the program to crash and also how to fix this code. Sub checkfortie() If txtPosition1.Text <> "" And txtPosition2.Text <> "" & txtPosition3.Text <> "" And _ txtPosition4.Text <> "" And txtPosition5.Text <> "" And txtPosition6.Text <> "" _ And txtPosition7.Text <> "" And txtPosition8.Text <> "" And txtPosition9.Text <> "" Then Catwins += 1 End If End Sub
If txtPosition1.Text <> "" And txtPosition2.Text <> "" & txtPosition3.Text <> "" And _
The problem is with one of yourand
s. You mistakenly used an &, which tries to do a bitwiseand
instead of a logicaland
. (Mixing up your C/C#/C++ with your VB?) This type of thing is hard to catch. Your brain sees what it wants to see. Roy. -
I am working on a program for tic tac toe. The program is using text boxes with click event so when the box is clicked it will populate with a X or O unless it is already populated. I have everything working except my subrotine which is called from the checkfor win to check for a tie. Here is the code I am trying to use to check for a tie. Can someone please help me with why this causes the program to crash and also how to fix this code. Sub checkfortie() If txtPosition1.Text <> "" And txtPosition2.Text <> "" & txtPosition3.Text <> "" And _ txtPosition4.Text <> "" And txtPosition5.Text <> "" And txtPosition6.Text <> "" _ And txtPosition7.Text <> "" And txtPosition8.Text <> "" And txtPosition9.Text <> "" Then Catwins += 1 End If End Sub
-
If txtPosition1.Text <> "" And txtPosition2.Text <> "" & txtPosition3.Text <> "" And _
The problem is with one of yourand
s. You mistakenly used an &, which tries to do a bitwiseand
instead of a logicaland
. (Mixing up your C/C#/C++ with your VB?) This type of thing is hard to catch. Your brain sees what it wants to see. Roy.