![]() |
Forum Index : Microcontroller and PC projects : Maximite BASIC issue
Author | Message | ||||
larny Guru ![]() Joined: 31/10/2011 Location: AustraliaPosts: 346 |
I have written a BASIC programme for my Maximite but it will not progress beyond Line 120. It gives me a message saying :- "[120} IF Vo(i) > 0.75 THEN .... Error Invalid syntax" But I cannot see anything wrong with the code. Here is the relevant part of the code. 115 i=1
116 DO 117 PRINT FORMAT$(Vt(i), "%4.3f"),;: IF V1(i) > 0.75 THEN PRINT FORMAT$(V1(i), "%4.3f"),; ELSE PRINT "x",; 118 IF Vo(i) > 0.75 THEN PRINT FORMAT$(Vo(i), "%4.3f"),; ELSE PRINT "y"; PRINT FORMAT$(Pc, "%4.0f") 119 PRINT #1, FORMAT$(Vt(i), "%4.3f"),;: IF V1(i) > 0.75 THEN PRINT #1, FORMAT$(V1(i), "%4.4f"),; ELSE PRINT #1, "x",;: 120 IF Vo(i) > 0.75 THEN PRINT #1, FORMAT$(Vo(i), "%4.3f"),; ELSE PRINT #1, "y",; PRINT #1, FORMAT$(Pc, "%4.0f") 121 i = i+1 122 123 LOOP UNTIL Vt(i) > 8 Any assistance will be appreciated. |
||||
Bizzie Senior Member ![]() Joined: 06/07/2014 Location: AustraliaPosts: 192 |
I do not think you can have an else clause in a one line IF statement. I would format it like this:- IF Vo(i) > 0.75 THEN PRINT #1, FORMAT$(Vo(i), "%4.3f"),; ELSE PRINT #1, "y",; PRINT #1, FORMAT$(Pc, "%4.0f") ENDIF Then there is the question of both , and ; at end of first print statement. I know the above takes up more lines but it makes it so much easier to read. Hope this helps. Rob White |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6266 |
It is difficult without a working piece of code to test with but: The end of line 120 ELSE PRINT #1, "y",; PRINT #1, FORMAT$(Pc, "%4.0f") You have two PRINT statements without a ':' between them. That is likely to be the problem You got away with it on line 118 but that's printing to the console so may be more forgiving. As Bizzie shows, you can combine the PRINT statements into one with ; or , between the outputs It is difficult to debug multi-statement lines so I would suggest that you start with one statement per line. I also would prefer you to ditch the line numbers. It is much easier to modify code if you don't have to keep renumbering every time you need a new line. Jim VK7JH MMedit |
||||
bigmik![]() Guru ![]() Joined: 20/06/2011 Location: AustraliaPosts: 2947 |
Hi Larny, @Jim, You just beat me by 2 minutes.. In the time it took me to login to post you had replied with what I agree is the cause of the syntax error. Regards, Mick Mick's uMite Stuff can be found >>> HERE (Kindly hosted by Dontronics) <<< |
||||
WhiteWizzard Guru ![]() Joined: 05/04/2013 Location: United KingdomPosts: 2931 |
Out of interest, do you not also need some ENDIF's in there for the MaxiMite? (I can't remember the syntax as it has been a while!) ![]() |
||||
drkl![]() Senior Member ![]() Joined: 18/10/2015 Location: HungaryPosts: 102 |
Hello, Try this: i=1 DO PRINT FORMAT$(Vt(i), "%4.3f"),; IF V1(i) > 0.75 THEN PRINT FORMAT$(V1(i), "%4.3f"),; ELSE PRINT "x",; ENDIF IF Vo(i) > 0.75 THEN PRINT FORMAT$(Vo(i), "%4.3f"),; ELSE PRINT "y"; PRINT FORMAT$(Pc, "%4.0f") ENDIF PRINT #1, FORMAT$(Vt(i), "%4.3f"),; IF V1(i) > 0.75 THEN PRINT #1, FORMAT$(V1(i), "%4.4f"),; ELSE PRINT #1, "x",; ENDIF IF Vo(i) > 0.75 THEN PRINT #1, FORMAT$(Vo(i), "%4.3f"), ELSE PRINT #1, "y",; PRINT #1, FORMAT$(Pc, "%4.0f") ENDIF i = i+1 LOOP UNTIL Vt(i) > 8] drkl |
||||
drkl![]() Senior Member ![]() Joined: 18/10/2015 Location: HungaryPosts: 102 |
Sorry, I made a mistake, the end of code: IF Vo(i) > 0.75 THEN PRINT #1, FORMAT$(Vo(i), "%4.3f"), ELSE PRINT #1, "y",; PRINT #1, FORMAT$(Pc, "%4.0f") ENDIF i = i+1 LOOP UNTIL Vt(i) > 8 drkl |
||||
Grogster![]() Admin Group ![]() Joined: 31/12/2012 Location: New ZealandPosts: 9585 |
TOTALLY agree. And I am a big line-number guy from the days of the Atari. When I first looked at numberless code, I could not see how the hell it worked WITHOUT the line numbers, but once you get the hang of it, it really is so much better and easier to work on structured code then line-numbered code, and I do speak as someone who was very in love with line numbers, so did not drop that willingly, but I am so glad that I did. Smoke makes things work. When the smoke gets out, it stops! |
||||
larny Guru ![]() Joined: 31/10/2011 Location: AustraliaPosts: 346 |
Thanks for the replies. I had an idea after posting this thread. I solved the issue by inserting a line feed at line 120 & I may ( I don't now remember) have added a : as someone suggested. However, I can see that it is better to insert one statement per line, so I'll adopt that method from now on. I'm not using Line Numbers. The numbers were inserted by MM Edit. I'm glad to see the last of them. Here is a view of the modified code which shows the line numbers. ![]() |
||||
WhiteWizzard Guru ![]() Joined: 05/04/2013 Location: United KingdomPosts: 2931 |
@larny A useful tip that helps make code easier to read is to 'indent tab' the lines of code between IF....ELSE and between ELSE....ENDIF. It also helps detect 'missing' ENDIF's which is a common problem ![]() Remember, this is just a 'tip' to make things easier for you; especially with long programs, or programs that you return to months later! So your code above would now look like this: i=1 DO PRINT FORMAT$(Vt(i), "%4.3f"),; IF V1(i) > 0.75 THEN PRINT FORMAT$(V1(i), "%4.3f"),; ELSE PRINT "x",; ENDIF IF Vo(i) > 0.75 THEN PRINT FORMAT$(Vo(i), "%4.3f"),; ELSE PRINT "y"; PRINT FORMAT$(Pc, "%4.0f") ENDIF PRINT #1, FORMAT$(Vt(i), "%4.3f"),; IF V1(i) > 0.75 THEN PRINT #1, FORMAT$(V1(i), "%4.4f"),; ELSE PRINT #1, "x",; ENDIF IF Vo(i) > 0.75 THEN PRINT #1, FORMAT$(Vo(i), "%4.3f"), ELSE PRINT #1, "y",; PRINT #1, FORMAT$(Pc, "%4.0f") ENDIF i = i+1 LOOP UNTIL Vt(i) > 8 EDIT I also like to add blank lines separating IF....ENDIF blocks |
||||
larny Guru ![]() Joined: 31/10/2011 Location: AustraliaPosts: 346 |
Thanks for the response. Yes the blank lines certainly make it clearer. |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |