![]() |
Forum Index : Microcontroller and PC projects : Help with code
Author | Message | ||||
allie Regular Member ![]() Joined: 06/10/2018 Location: CanadaPosts: 70 |
Hi all! I'm playing around in writing my code for the CMM2 Gen2 for my Lath and Milling machine project with MMBasic 5.07.01. I know I don't have to use line numbers, I'm old school (commodore 64 days). And the way you use the GOSUB routines has changed. For now I still like using them. I'll change it later after I get a working program. Most of what I have now works fine, except for this. I'll leave out comments for now. 15 PRINT : PRINT 18 D$="NOTHING" 20 PRINT" L FOR LATH OR M FOR MILL" 25 PRINT : PRINT 30 INPUT" L OR M" ;LM$ 35 PRINT : PRINT 40 GOSUB 1000 'ROUTINE FOR PRINT" XI FOR X AXIS IN * XO FOR X AXIS OUT" SAME Y AXIS ' EVERY THING WORKS GOOD UP TO HERE ' PROBLEM WITH THESE LINES 42 PRINT : PRINT : PRINT"LM$ =" ;LM$ 45 IF LM$ <> "L" OR LM$ <> "M" THEN CLS : GOTO 20 ' WHEN LM$ = L OR M IT CLS SCREEN AND GOES TO LINE 20 ' IT SHOULD GO TO THE NEXT LINE. 50 IF LM$="L"THEN INPUT" INPUT FOR LATH XI * XO * YI * YO";D$ REGARDS ALLIE Edited 2025-06-17 09:16 by allie |
||||
EDNEDN Senior Member ![]() Joined: 18/02/2023 Location: United StatesPosts: 136 |
45 IF LM$ <> "L" OR LM$ <> "M" THEN CLS : GOTO 20 Did you mean: 45 IF LM$ <> "L" AND LM$ <> "M" THEN CLS : GOTO 20 Because the original If condition is always going to evaluate to being true. . Edited 2025-06-17 09:34 by EDNEDN |
||||
phil99![]() Guru ![]() Joined: 11/02/2018 Location: AustraliaPosts: 2558 |
Option B:- 45 If Not(LM$ = "L" Or LM$ = "M") THEN CLS : GOTO 20 Should do the same thing. |
||||
allie Regular Member ![]() Joined: 06/10/2018 Location: CanadaPosts: 70 |
I was thinking the or would work as I used it in other places. Thanks for the input. I changed it to (and) and all is good. Regards Allie |
||||
allie Regular Member ![]() Joined: 06/10/2018 Location: CanadaPosts: 70 |
I tried this also and it worked too. Thank you both for the quick response. Regards Allie |
||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7784 |
if instr("LMlm",LM$)=0 then cls goto 20 endif It's not a great idea to use multi-statement lines that begin with an IF statement. There is the danger that commands may not do what you expect! Far better to make use of ELSE and ENDIF simply because they are available and make your code much clearer. When someone is entering keyboard commands you need to make sure that the character case will be detected or nothing will happen - and you'll have a confused user! So: 32 LM$ = UCASE$(LM$) will make sure that your string comparisons will work, even if they enter lower or mixed case characters. INSTR() is a great function for this sort of thing. It will search the test string and return the position of the search string or zero if it's not found. In the above example it will return 1 for "L", 2 for "M", 3 for "l" or 4 for "m". Or you could use the full IF/ENDIF tree with slight rearrangement: 20 CLS 22 PRINT:PRINT 24 PRINT" L FOR LATH OR M FOR MILL" 25 PRINT : PRINT 30 INPUT" L OR M" ;LM$ 32 LM$ = UCASE$(LM$) 35 PRINT : PRINT IF LM$ = "L" then 'do something with the lathe ELSE IF LM$ = "M" then 'do something with the mill ELSE GOTO 20 ENDIF Jumping out of the IF/ENDIF with a GOTO is a bit naughty (it used to mess the return stack up), but MMBasic is quite well behaved. :) Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |