'If Then' syntax error limits #macro usage.

Buzby

Senior Member
Hi,

I can 'sort of' see why "IF 125 < 126 THEN" is flagged as a syntax error, even though it it is a perfectly logical, but useless, construction.
The syntax error is generated by the 125, which is a constant, but the compiler is expecting a variable.

This can be proved by trying "IF 125 < b0 THEN" which gives the same error, but swapping the terms to put the variable on the left is OK.
It means you can test for 'is MyHeight less than 6ft', but not 'is 6ft greater than MyHeight'.

This is not usually a problem, as it's easy to swap the terms and change the comparison.

The problem comes when you pass a constant as a parameter to a #macro, and that constant ends up in a comparison with another constant.

I cannot see a way around this, other than copying the parameter to a variable within the #macro itself, then doing the comparison, which seems to rather defeat the object of passing a parameter in the first place.

Is there a specific reason why the compiler can't have a constant after the IF ?.
Could it be fixed in a compiler revision, or is it built into the firmware ?.

Cheers,

Buzby
IfThenSyntaxError.PNG
 

Technical

Technical Support
Staff member
If expects a variable, that is simply the way it was designed.

A constant / constant shouldn't ever be necessary, even with macros. What are you trying to do?
 

Buzby

Senior Member
I have a macro which is used many times in my code.

The value passed to the macro is used by comparisons within the macro to determine actions.

Some calls uses a variable for the parameter, where the calling code has 'calculated' the action it wants the macro to take.
Other calls use constants, when the action needs to be specified exactly.
 
Top