Menu
JAQForum Ver 19.10.27

Forum Index : Microcontroller and PC projects : Help with code

Posted: 11:12pm
16 Jun 2025
Copy link to clipboard
allie
Regular Member

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
 
Posted: 11:31pm
16 Jun 2025
Copy link to clipboard
EDNEDN
Senior Member

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
 
Posted: 12:13am
17 Jun 2025
Copy link to clipboard
phil99
Guru


Option B:-
45 If Not(LM$ = "L" Or LM$ = "M") THEN CLS : GOTO 20
Should do the same thing.
 
Posted: 12:34am
17 Jun 2025
Copy link to clipboard
allie
Regular Member

  EDNEDN said  
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.


.


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
 
Posted: 12:37am
17 Jun 2025
Copy link to clipboard
allie
Regular Member

  phil99 said  Option B:-
45 If Not(LM$ = "L" Or LM$ = "M") THEN CLS : GOTO 20
Should do the same thing.


I tried this also and it worked too.
Thank you both for the quick response.

Regards Allie
 
Posted: 06:44am
17 Jun 2025
Copy link to clipboard
Mixtel90
Guru



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. :)
 


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