Syntax Error

Duane S

New Member
I've got this syntax error, in a 28X1 program, and I'm trying to figure out what to do to fix it.

Here's the code:

if head > ForwardLeft and head < 150 then head = head - 15

And here's the response after a syntax check:

---------------------------
Compile Error...
---------------------------
if head > ForwardLeft and head < 150 then head = head - 15

Error: label_conv: VAR is already defined!
---------------------------
OK
---------------------------


I'm just trying to adjust the value of "head" if it meets the conditions. I know that "head" has already been defined as a symbol in my init routine.

I've tried playing with things, but don't understand what I'm doing wrong.

Help !

Thanks,

Duane S

Wilson, NC USA
 
Last edited:

xzoqick

New Member
workaround

I too tried your code:

if head > ForwardLeft and head < 150 then head = head - 15

and got the same error message.



I tried:

if head > ForwardLeft and head < 150 then
head = head - 15: endif

and it syntax checks fine.

Here are two alternatives:

if w0 > w1 and w0 < 150 then: w0 = w0 - 15: endif

or

if w0 > w1 and w0 < 150 then
w0 = w0 - 15
endif

If you just need to get it running then that's the workaround.
If you need to know why, then sorry, I don't know and can't help.
 
Last edited:

westaust55

Moderator
IF...THEN syntax/format

The syntax/format for the IF…THEN command is:
IF variable ?? value {AND/OR variable ?? value ...} THEN
{code}
ELSEIF variable ?? value {AND/OR variable ?? value ...} THEN
{code}
ELSE
{code}
ENDIF
To my knowledge, the only time you can have something immediately after the THEN keyword is when you are transferring to another part of the program. That is GOTO label or GOSUB label

So the following are valid
IF variable ?? value THEN label
IF variable ?? value THEN GOTO label
IF variable ?? value THEN GOSUB label

In all other cases such as when maths are involved, the body of the code must be on the next line and MUST conclude with ENDIF

See manual 2 page 71 and ALSO page 72 for more details on single-line versus multi-line use. Its all there to be read.
 

Duane S

New Member
Thank you, xzoqick, for your suggestions, and the effort. I tried it, but no luck for me. I'll try again tomorrow, when I'm not so frustrated.

Sometimes it helps to just step away from a problem, and look at it again later when you've got a fresh mind.

Thanks,

Duane S

Wilson, NC USA
 

Duane S

New Member
The syntax/format for the IF&#8230;THEN command is:


To my knowledge, the only time you can have something immediately after the THEN keyword is when you are transferring to another part of the program. That is GOTO label or GOSUB label

So the following are valid
IF variable ?? value THEN label
IF variable ?? value THEN GOTO label
IF variable ?? value THEN GOSUB label

In all other cases such as when maths are involved, the body of the code must be on the next line and MUST conclude with ENDIF

See manual 2 page 71 and ALSO page 72 for more details on single-line versus multi-line use. Its all there to be read.
I apologize. I did not show it in my post, but there IS an endif 2 lines below the SYNTAX ERROR response that I showed from the syntax check. I'm about brain dead now, but I'll look into your suggestion tomorrow. And, honestly, I didn't know about the single line / multi-line thing, but it makes sense. The error messsage was confusing though......

Thank you !

Duane S

Wilson, NC USA

P.S. I Tried your suggestion NOW, because I KNEW that I would not be able to go to sleep if I did not. You were correct. The syntax check got past that line, and stopped again at the next place I'd made the same mistake. :(

I'll re-read the suggested parts of the manual tomorrow.

Thank you again ! Now I can sleep tonight.

Duane S
 
Last edited:

BITMOVER

Member
Try This..

if head > ForwardLeft and head < 150 then:head = head - 15

(Note colon betwen then and head)

I don't really understand this syntax issue but I've run into it before. To troubleshoot I usually break the long line into shorter lines so the error checker points more closely to the bad code section.
 

BCJKiwi

Senior Member
The syntax error is advising that 'head' is already defined and the code is trying to redefine it.

a 'Let' is required as the intention is to change the value stored in 'head', not redefine it;

Code:
if head > ForwardLeft and head < 150 then [B][I]LET[/I][/B] head = head - 15
or a new statement ":" = new line which is equivalent to;
Code:
if head > ForwardLeft and head < 150 then
   head = head - 15
endif
 
Last edited:

westaust55

Moderator
using the new line command “:” as suggested by BCJKiwi to make it “look” like muli-line syntax then the program line should/could read as:

if head > ForwardLeft and head < 150 then : head = head – 15 : endif


Note that (as per the manual 2) The ‘let’ keyword is optional.
 
Last edited:

hippy

Technical Support
Staff member
The error messsage was confusing though......
"Error: label_conv: VAR is already defined!"

Makes perfect sense to those of us who write compilers but I'll also admit to a "Huh?" when I first encountered that one. While diagnostic messages are useful for compiler writers to explain exactly why something failed, compiler users want to know what failed in simple English.

"Label expected" would make more sense to most programmers.
 

Duane S

New Member
Thanks, to all of you that replied to my plea for help. Actually, westaust55's reply last night got me on the right track, and I was able to get some sleep after all.

When I broke my code into multiple lines today, it worked just fine.

It's been some 20+ years since I've played with BASIC much. And I've forgotten more than I ever knew. (plus each version of BASIC has it's own little quirks that we must learn).

I'd read the single line / multi-line thing, in the manual, but my feeble brain had not absorbed it.

I'll also look into the other suggestions. I'm here to learn, and I know that there are many different ways to approach a problem.

Thank you, all. I love this forum. :)

Duane S
Wilson, NC USA
 
Last edited:
Top