|
Forum Index : Microcontroller and PC projects : Error: Unexpected text
| Author | Message | ||||
| lew247 Guru Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
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 error |
||||
| matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 10569 |
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 missing |
||||
| lew247 Guru Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
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 KingdomPosts: 10569 |
You still have this line which is incorrect syntax |
||||
| Azure Guru Joined: 09/11/2017 Location: AustraliaPosts: 446 |
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 KingdomPosts: 1702 |
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 ELSE |
||||
redrok![]() Senior Member Joined: 15/09/2014 Location: United StatesPosts: 209 |
Hi lew247;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 StatesPosts: 769 |
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 StatesPosts: 3466 |
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 StatesPosts: 769 |
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 KingdomPosts: 1702 |
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 StatesPosts: 769 |
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 NY |
||||
| lizby Guru Joined: 17/05/2016 Location: United StatesPosts: 3466 |
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 KingdomPosts: 1702 |
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 StatesPosts: 769 |
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 KingdomPosts: 1702 |
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 |
||||
| The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |