Syntax error with if statement..

Gary Miyakawa

Active Member
Licensed User
Longtime User
Ok, I've been writing this stuff for over a year and just bumped into this... I'm pretty sure it's something I'm doing wrong but I don't get it.. Someone please clue me in...

Here is the sample code that is cause me trouble.

B4X:
'Activity module
Sub Process_Globals
End Sub
Sub Globals
   Dim f As Boolean
End Sub
Sub Activity_Create(FirstTime As Boolean)
   f = True
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub btnSettings
   If f = True
End Sub

When compiled, I get a "Syntax error (missing parameter)." on the If statement. "Word: true"...

Let me know where I'm wrong!

Thanks,

Gary M
 

raytronixsystems

Active Member
Licensed User
Longtime User
I usually get all errors that are hard to identify when I forget the 'Then' keyword after an 'If' statement. I sometimes look for hours and wonder what went wrong then realize what I forgot. This is a very common mistake that probably all of us have encountered at one time or another. My background primarily in 'C/C++' and we didn't have the 'Then' construct. Maybe a future version of the B4a compiler could look for missing 'Then' and 'Endif' keywords and alert the user.

Best Wishes,
Ray
 
Upvote 0

MrRey

Member
Licensed User
Longtime User
As a fellow Ray, I know the feeling. I couldn't figure out why an ImageView wasn't showing. I later realized I had set Visible to false in Designer. :D
 
Upvote 0

ukimiku

Active Member
Licensed User
Longtime User
Me too. Before, I was working with a dialect of Basic that simply didn't require the THEN keyword:

B4X:
if a = 3
   ... code to be executed iff a = 3
else
   ...
end if

I think the THEN is redundant, and should be made voluntary instead of obligatory in a future release of B4A. Like in a FOR... NEXT loop, the variable after the NEXT is not really necessary (and not even legal to supply in B4A). Out of habit, I sometimes forget to write THEN and, like you, wonder what may have caused this strange compilation problem.

Regards,
 
Upvote 0
Top