Compiling error "Missing Keyword: end sub" while not needed

TrueBypass

Member
Licensed User
Hello everyone.
I wrote the following code in my project:
B4X:
Sub Activity_Touch (Action As Int, X As Float, Y As Float)
   If Y > Ball.Height / 2 + Ball.Top AND Line < 5 Then AND Bln = True
      Bln = False
      Line = Line + 1
      Ball.Top = Ball.Top + Ball.Height
      Tmr.Enabled = True
   Else
      If Y < Ball.Height /2 + Ball.Top AND Line > 1 Then AND Bln = True
         Bln = False
         Line = Line - 1
         Ball.Top = Ball.Top - Ball.Height 
         Tmr.Enabled = True
      End If        'line 45
   End If
End Sub
And when I try to compile it, I get the error:
Error parsing program.
Error description: Missing Keyword: end sub
Occurred on line: 45
End If
Although this is not a new sub.

Can I get some help? Thanks.
 

klaus

Expert
Licensed User
In your code you have a condition after the Then keyword!
B4X:
Sub Activity_Touch (Action As Int, X As Float, Y As Float)
  If Y > Ball.Height / 2 + Ball.Top AND Line < 5 [COLOR=red]Then[/COLOR] AND Bln = True
    Bln = False
    Line = Line + 1
    Ball.Top = Ball.Top + Ball.Height
    Tmr.Enabled = True
  Else
    If Y < Ball.Height /2 + Ball.Top AND Line > 1 [COLOR=red]Then[/COLOR] AND Bln = True
      Bln = False
      Line = Line - 1
      Ball.Top = Ball.Top - Ball.Height 
      Tmr.Enabled = True
    End If        'line 45
  End If
End Sub
You code could look like this:
B4X:
Sub Activity_Touch (Action As Int, X As Float, Y As Float)
  If Bln = True
    If Y > Ball.Height / 2 + Ball.Top AND Line < 5 Then
      Line = Line + 1
      Ball.Top = Ball.Top + Ball.Height
      Tmr.Enabled = True
    Else If Y < Ball.Height /2 + Ball.Top AND Line > 1 Then
      Line = Line - 1
      Ball.Top = Ball.Top - Ball.Height 
      Tmr.Enabled = True
    End If
    Bln = False
  End If
End Sub
Best regards.
 

TrueBypass

Member
Licensed User
Oh, thanks.
I didn't notice that since I wrote the "AND Bln = True" later on and I forgot to change it.
:signOops:
(Problem solved)
 
Top