Results 1 to 5 of 5

Thread: Issues with Basic Test Program

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2021
    Posts
    2

    Question Issues with Basic Test Program

    Hey everyone,

    I have tried to program a simple game in Basic. The game which is called Tic tac toe with a multi-page query.
    When starting the game I always get the error message Else without If.
    I can't find the error.

    The game field is 12 buttons from top left to bottom right. The button is called as name "lblspieler".

    Can you help me further? Thanks.

    Code:
    Code:
    Private Sub Command1_Click(Index As Integer)
    If lblSpieler.Caption = "1" Then
       lblSpieler.Caption = "2"
    Command1(Index).Caption = "X"
    Command1(Index).Enabled = False
    ElseIf lblSpieler.Caption = "2" Then
    lblSpieler.Caption = "1"
    Command1(Index).Caption = "O"
    Command1(Index).Enabled = False
    
    ElseIf Command1(0).Caption = "X" And Command1(1).Caption = "X" And Command1(2).Caption = "X" Then MsgBox "Spieler 1 hat gewonnen!"
    Command1(Index).Enabled = False
    
    ElseIf Command1(3).Caption = "O" And Command1(4).Caption = "O" And Command1(5).Caption = "O" Then MsgBox "Spieler 2 hat gewonnen!"
    Command1(Index).Enabled = False
    
    ElseIf Command1(6).Caption = "X" And Command1(7).Caption = "X" And Command1(8).Caption = "X" Then MsgBox "Spieler 1 hat gewonnen!"
    Command1(Index).Enabled = False
    
    ElseIf Command1(0).Caption = "O" And Command1(3).Caption = "O" And Command1(6).Caption = "O" Then MsgBox "Spieler 2 hat gewonnen!"
    Command1(Index).Enabled = False
    
    ElseIf Command1(1).Caption = "X" And Command1(4).Caption = "X" And Command1(7).Caption = "X" Then MsgBox "Spieler 1 hat gewonnen!"
    Command1(Index).Enabled = False
    
    ElseIf Command1(2).Caption = "O" And Command1(5).Caption = "O" And Command1(8).Caption = "O" Then MsgBox "Spieler 2 hat gewonnen!"
    Command1(Index).Enabled = False
    
    ElseIf Command1(0).Caption = "X" And Command1(4).Caption = "X" And Command1(8).Caption = "X" Then MsgBox "Spieler 1 hat gewonnen!"
    Command1(Index).Enabled = False
    
    ElseIf Command1(2).Caption = "O" And Command1(4).Caption = "O" And Command1(6).Caption = "O" Then MsgBox "Spieler 2 hat gewonnen!"
    Command1(Index).Enabled = False
    End If
    End Sub
    Name:  test.png
Views: 98
Size:  8.1 KB

  2. #2
    Frenzied Member
    Join Date
    Nov 2017
    Posts
    1,565

    Re: Issues with Basic Test Program

    You have a bunch of code formatted like this:

    Code:
    ElseIf (Condition) And (Condition) Then do something
      do something further
    ElseIf ...
    When you put code on the same line after a "Then" keyword, only that code is considered "inside" that ElseIf block.

    Using my example above, the fix is:

    Code:
    ElseIf (Condition) And (Condition) Then
      do something
      do something further
    ElseIf ...

  3. #3
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,294

    Re: Issues with Basic Test Program

    I would assume that any line that has "Then" followed by code on the same line, that code needs to be moved to a new line.
    VB6 supports "If Then End If" Blocks, and it supports In-line "If Then" statement without End If where the code follows the Then. You are messing up the syntax so it thinks you have In-Line "If Then" statements.
    "Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930

  4. #4
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    7,841

    Re: Issues with Basic Test Program

    all that aside...your image shows 9, not 12, command buttons....?
    Sam I am (as well as Confused at times).

  5. #5

    Thread Starter
    New Member
    Join Date
    Mar 2021
    Posts
    2

    Re: Issues with Basic Test Program

    Quote Originally Posted by SamOscarBrown View Post
    all that aside...your image shows 9, not 12, command buttons....?
    Thank you for your reply. I am apologized about the numer. I mean 9 buttons. Sorry.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width