For the life of me I cannot figure out this error...
Else without If
I'm writing a simple Tic Tac Toe Program where users take turn putting their x's or o's on the board...I'm still in the stage of deciding which letter gets placed. here is my code...I have the same thing for all Commands, except that they change a differant commands caption it corrosponds...command 1 is the upper left box 2 is upper middle and so on right to left all the way down...
VB Code:
Public Sub Form_Load()
Dim whoturn As Boolean
whoturn = False
End Sub
Public Sub Command1_Click()
If whoturn = False Then whoturn = True
Else: whoturn = False
If whoturn = True Then Command1.Caption = "X"
Else
Command1.Caption = "O"
End Sub
Again i get the above error, and Idk what i'm doing wrong...any suggestions??
public local? what do you mean can u tell me what to do then explain why i have to do it...i'm really confused i've been working on this what YOU would considere simple thing for like 1.5 hours
Originally posted by thurst0n public local? what do you mean can u tell me what to do then explain why i have to do it...i'm really confused i've been working on this what YOU would considere simple thing for like 1.5 hours
Ok, I've tried everything, it simply doesnt work i keep getting the same error Else witout If, Would someone please write the code (it's short) and post it and tell me why it happens
Originally posted by thurst0n Ok, I've tried everything, it simply doesnt work i keep getting the same error Else witout If, Would someone please write the code (it's short) and post it and tell me why it happens
Post the code you're using
This works in .NET:
VB Code:
Public whoturn As Boolean
Public Sub Form_Load()
whoturn = False
End Sub
Public Sub Command1_Click()
If whoturn = False Then
whoturn = True
Else
whoturn = False
End If
If whoturn = True Then
Command1.Caption = "X"
Else
Command1.Caption = "O"
End If
End Sub
I don't have VB 6 in front of me, but I doubt it's much different.
note that the first one does not require an end if, but it only works on one line (the things after 'then')
the second one can be used on multiple lines until the end if.
more stuff
if blah = 1 then msgbox "hello" else msgbox "bye"
and
if blah = 1 then
msgbox "hello"
else
msgbox "bye"
end if