Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 05:06 11 Nov 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Error: Unexpected text

Author Message
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 12:13pm 14 Mar 2018
Copy link to clipboard 
Print this post

This is a weird one
It works fine sometimes for hours at a time then crashes
Other times it comes up with the error when I run the program
E100 Micromite

[quote][109] Else press2$ < press1$ Then 'IF tomorrow's pressure is lower then todays
Error: Unexpected text: press2$ Å press1$ ² 'IF tomorrow's pressure is lower then todays[/quote]

The actual code is
[code]IF press1$ = press2$ then 'IF tomorrow's pressure = todays
Text 420,130," ",LM,4,1,RGB(48,35,29) ,RGB(48,35,29) 'Then do nothing
else
IF press1$ > press2$ then 'IF tomorrow's pressure is higher then todays
Text 420,130,ZA,LM,8,2,rgb(green),RGB(48,35,29) 'draw up arrow Left side of screen
else press2$ < press1$ then 'IF tomorrow's pressure is lower then todays
Text 420,130,ZB,LM,8,2,rgb(red),RGB(48,35,29) 'draw down arrow
END IF
end if
end if
IF press1$ = press2$ then 'IF tomorrow's pressure = todays
Text 760,130," ",LM,4,1,RGB(48,35,29) ,RGB(48,35,29) 'Then do nothing
else
IF press1$ > press2$ then 'IF tomorrow's pressure is higher then todays
Text 760,130,ZA,LM,8,2,rgb(green),RGB(48,35,29) 'draw up arrow Right side of screen
else press2$ < press1$ then 'IF tomorrow's pressure is lower then todays
Text 760,130,ZB,LM,8,2,rgb(red),RGB(48,35,29) 'draw down arrow
END IF
end if
end ifF [/code]

This is what Terra term Terminal shows


EDIT: I know it looks like I've put a weird character in there but it's just the standard UK keyboard no control codes or anything
EDIT2: I deleted it and typed it out again and I have the exact same errorEdited by lew247 2018-03-15
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10569
Posted: 12:30pm 14 Mar 2018
Copy link to clipboard 
Print this post

You are missing an ENDIF and you have an ELSE with a conditional but no IF.
Start by getting your indentation correct for what you are intending and then you will see what is missingEdited by matherp 2018-03-15
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 12:38pm 14 Mar 2018
Copy link to clipboard 
Print this post

I edited the code to show the full section of code Peter
I "think" each section should have 3 END IF's
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10569
Posted: 12:42pm 14 Mar 2018
Copy link to clipboard 
Print this post

You still have this line which is incorrect syntax

  Quote  else press2$ < press1$ then
 
Azure

Guru

Joined: 09/11/2017
Location: Australia
Posts: 446
Posted: 12:46pm 14 Mar 2018
Copy link to clipboard 
Print this post

Hopefully this is it tidied up a little with some indenting
[code]
IF press1$ = press2$
THEN 'tomorrow's pressure = todays
Text 420,130," ",LM,4,1,RGB(48,35,29),RGB(48,35,29) 'do nothing
ELSE
IF press1$ > press2$
THEN 'tomorrow's pressure is higher then todays
Text 420,130,ZA,LM,8,2,rgb(green),RGB(48,35,29) 'draw up arrow
ELSE
IF press2$ < press1$
THEN 'tomorrow's pressure is lower then todays
Text 420,130,ZB,LM,8,2,rgb(red),RGB(48,35,29) 'draw down arrow
END IF
END IF
END IF
[/code]
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 12:47pm 14 Mar 2018
Copy link to clipboard 
Print this post

Thanks Peter, I never spotted that and I must have looked through it almost a hundred times trying to figure it out
Just trying it now with the correct syntax

I never realised the IF wasn't necessary when using ELSEEdited by lew247 2018-03-15
 
redrok

Senior Member

Joined: 15/09/2014
Location: United States
Posts: 209
Posted: 05:15pm 14 Mar 2018
Copy link to clipboard 
Print this post

Hi lew247;
  lew247 said   Thanks Peter, I never spotted that and I must have looked through it almost a hundred times trying to figure it out
Just trying it now with the correct syntax

I never realized the IF wasn't necessary when using ELSE
Well sometimes?
There is a bit of syntax difference between the "Single Line IF" and the "Multi-Line IF".

You must carefully read the descriptions in the manual.
The multi-line form is the "formal" version.
However sometimes the single-line version is more convenient.

Similarly the "DOs".

redrok
 
Paul_L
Guru

Joined: 03/03/2016
Location: United States
Posts: 769
Posted: 09:02pm 14 Mar 2018
Copy link to clipboard 
Print this post

Hi Lewis,

I believe that the multiline IF THEN ELSEIF ELSE ENDIF construction has some tricks in it. There probably should not be a space between ELSE and IF or between END and IF and THEN should be on the same line with the condition it is testing.

I think what you have here is a single composite test, not multiple ones. Maybe this will work.
IF press1$ = press2$ THEN 'tomorrow's pressure = todays
Text 420,130," ",LM,4,1,RGB(48,35,29),RGB(48,35,29) 'do nothing
ELSEIF press1$ > press2$ THEN 'tomorrow's pressure is higher then todays
Text 420,130,ZA,LM,8,2,rgb(green),RGB(48,35,29) 'draw up arrow
ELSEIF press2$ < press1$ THEN 'tomorrow's pressure is lower then todays
Text 420,130,ZB,LM,8,2,rgb(red),RGB(48,35,29) 'draw down arrow
ELSE
?"UBLEWIT!":END 'your code should never get here, this is an error trap
ENDIF


Paul in NY
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3466
Posted: 01:25pm 15 Mar 2018
Copy link to clipboard 
Print this post

Or, since only 3 conditions are possible (=,<,>):
[code]
IF press1$ = press2$ THEN 'tomorrow's pressure = todays
Text 420,130," ",LM,4,1,RGB(48,35,29),RGB(48,35,29) 'do nothing
ELSEIF press1$ > press2$ THEN 'tomorrow's pressure is higher then todays
Text 420,130,ZA,LM,8,2,rgb(green),RGB(48,35,29) 'draw up arrow
ELSE 'tomorrow's pressure is lower then todays
Text 420,130,ZB,LM,8,2,rgb(red),RGB(48,35,29) 'draw down arrow
ENDIF
[/code]

PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
Paul_L
Guru

Joined: 03/03/2016
Location: United States
Posts: 769
Posted: 01:43pm 15 Mar 2018
Copy link to clipboard 
Print this post

In the even that OPTION EXPLICIT is not used the possible fourth condition is that either press1$ or press2$ might not be assigned. If the ELSE = UBLEWIT! test is performed it will trap that event. If it is not there I don't really know what the MMBASIC interpreter will do. In any event the ELSE test could be modified to do something other than END.

Paul in NY
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 02:04pm 15 Mar 2018
Copy link to clipboard 
Print this post

Weirdly I couldn't get it to work until I put it in a subroutine
This works
[code]SUB PRESSICON
if press1$ > press2$ then 'IF tomorrow's pressure is higher then todays
Text 420,130,ZA,LM,8,2,rgb(green),RGB(48,35,29) 'draw up arrow Left side of screen
end if
if press2$ < press1$ then 'IF tomorrow's pressure is lower then todays
Text 420,130,ZB,LM,8,2,rgb(red),RGB(48,35,29) 'draw down arrow
END IF
if press1$ > press2$ then 'IF tomorrow's pressure is higher then todays
Text 765,130,ZA,LM,8,2,rgb(GREEN),RGB(48,35,29) 'draw up arrow Left side of screen
end if
if press2$ < press1$ then 'IF tomorrow's pressure is lower then todays
Text 765,130,ZB,LM,8,2,rgb(red),RGB(48,35,29) 'draw down arrow
END IF
END SUB[/code]

I am using OPTION EXPLICIT btw
All the code does is print an arrow either side of the temp pressure showing if it's going up or down tomorrow.
 
Paul_L
Guru

Joined: 03/03/2016
Location: United States
Posts: 769
Posted: 03:14am 16 Mar 2018
Copy link to clipboard 
Print this post

You test for press1$ > press2$ and press2$ < press1$ twice each. Why?

It would run faster and be more readable if you combined it into a single IF. Readability is extremely important. In five years you will come back and take a look at this code and you better be able to figure out what you were trying to do immediately.


SUB PRESSICON
if press1$ > press2$ then 'IF tomorrow's pressure is higher then todays
Text 420,130,ZA,LM,8,2,rgb(green),RGB(48,35,29) 'draw up arrow Left side of screen
Text 765,130,ZA,LM,8,2,rgb(GREEN),RGB(48,35,29) 'draw up arrow Left side of screen
elseif press2$ < press1$ then 'IF tomorrow's pressure is lower then todays
Text 420,130,ZB,LM,8,2,rgb(red),RGB(48,35,29) 'draw down arrow
Text 765,130,ZB,LM,8,2,rgb(red),RGB(48,35,29) 'draw down arrow
ENDIF
END SUB 'PRESSICON


I like to stick the name of the SUB or FUNCTION in a remark after the END SUB or END FUCNCTION statement. It's easier to keep track of which SUB you're ending that way. I sometimes even put a remark after an ENDIF statement.

Also, note that I don't have a space between END and IF or between ELSE and IF. END requires a trailing space when you end a SUB or FUNCTION. The space is optional in ENDIF or ELSEIF but it's a good idea to leave it out. That way you can search for "END_" and find all the function and sub endings.

Paul in NYEdited by Paul_L 2018-03-17
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3466
Posted: 01:34pm 16 Mar 2018
Copy link to clipboard 
Print this post

Note that

if press1$ > press2$ then

and

if press2$ < press1$ then

are equivalent. In words, if press1$ is greater than press2$, then it is necessarily true that press2$ is less than press1$.

I don't think that is what you want to do.

It usually helps if you keep the variables in the same order when you do comparisons.

PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 02:19pm 16 Mar 2018
Copy link to clipboard 
Print this post

I have it working much better now
[code]
SUB PRESSICON
if prs2tmp > prs1tmp then 'IF tomorrow's pressure is higher then todays
Text 405,130,ZA,LM,8,2,rgb(green),RGB(48,35,29) 'draw up arrow Left side of screen
Text 760,130,ZA,LM,8,2,rgb(GREEN),RGB(48,35,29) 'draw up arrow Left side of screen
elseif prs2tmp < prs1tmp then 'IF tomorrow's pressure is lower then todays
Text 405,130,ZB,LM,8,2,rgb(red),RGB(48,35,29) 'draw down arrow
Text 760,130,ZB,LM,8,2,rgb(red),RGB(48,35,29) 'draw down arrow
ENDIF
END SUB[/code]
 
Paul_L
Guru

Joined: 03/03/2016
Location: United States
Posts: 769
Posted: 11:19pm 17 Mar 2018
Copy link to clipboard 
Print this post

Great! Now load it into MMEdit and use the <P>rogram <F>ormat in order to finally see the structures!

Paul in NY
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 11:22pm 17 Mar 2018
Copy link to clipboard 
Print this post

  Paul_L said   Great! Now load it into MMEdit and use the <P>rogram <F>ormat in order to finally see the structures!

Paul in NY

I'd actually spend a long time today going through the whole code and formatting it...
I just tried MMEdit and it made 1 change
I will remember it in future though
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025