Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 11:12 01 Aug 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 : Odd behaviour MMBASIC 5.04.07...

Author Message
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9610
Posted: 11:52pm 23 Dec 2017
Copy link to clipboard 
Print this post

Code that was working just fine in earlier versions, now does very odd things with the "ON" command.

Take this section of code:

  Quote  GET_PASSWORD:
KEY=0:LCD_EXIT=0:LCD_OK=0:Y=0 'Clear flags
Watchdog WDT
If DEBUG Then Print "Watchdog reset.(GET PASSWORD)"
If DEBUG Then Print "Get Password."
PAGE 2,4
If PROMPTING Then
CHDIR "\SYSTEM"
PLAY WAV
"PASS.NSF"
Endif
CtrlVal(PASSWORD)="##PASSWORD"
GUI Interrupt EXIT_OK
Timer=0
Do
If LCD_EXIT Then
LCD_EXIT=
0
If DEBUG Then Print "EXIT button touched.(get password)"
Y=
1
Endif
If LCD_OK Then
LCD_OK=
0:Y=0
If DEBUG Then Print "OK button touched.(get password)"
If CtrlVal(PASSWORD)=STDPWD$ Then
If DEBUG Then Print "Password correct."
If PROMPTING Then
CHDIR "\SYSTEM"
PLAY WAV
"GRANTED.NSF"
Endif
Y=
2
ELSE
SYSMSG$=
"Password incorrect.(database access)"
If DEBUG Then Print SYSMSG$
If SYSLOG Then WRITE_SYSLOG(SYSMSG$)
CtrlVal(ADWI)="INCORRECT."
PAGE 3 'Access denied
GUI BEEP 1000
If PROMPTING Then
CHDIR "\SYSTEM"
PLAY WAV
"DENIED.NSF"
Endif
Pause 3000
Y=
1
Endif
Endif
If Y Then EXIT Do
If Timer>=SSDELAY Then goto START
LOOP
ON Y goto START,DATABASE_EDITOR


Routine used to get a password, was working fine, now touching the EXIT button causes it to go directly to the database entries, when it should go back to the main menu.

If I put a PRINT Y after the loop, but before the ON command like this:

  Quote   Endif
Endif
If Y Then EXIT Do
If Timer>=SSDELAY Then goto START
LOOP
Print Y
ON Y goto START,DATABASE_EDITOR


The code then DOES go back to the main menu, but it DOES NOT actually print out the value of Y.

If I change the code again to add a 2nd PRINT line like this:

  Quote   Endif
Endif
If Y Then EXIT Do
If Timer>=SSDELAY Then goto START
LOOP
Print Y
Print Y
ON Y goto START,DATABASE_EDITOR


Then that also works to go back to the main menu, and prints the value of Y on the console ONCE - even though it should be twice.....

Remove both "PRINT Y" commands, and change to END so the program should stop at that point, and it DOES NOT:

  Quote   Endif
Endif
If Y Then EXIT Do
If Timer>=SSDELAY Then goto START
LOOP
END
ON Y goto START,DATABASE_EDITOR


If I ask the console for "PRINT Y" at this point, it is one - just as it should be.

If I change the PRINT Y's to "One" and "Two" like this:

  Quote   Endif
Endif
If Y Then EXIT Do
If Timer>=SSDELAY Then goto START
LOOP
Print "One..."
Print "Two..."
ON Y goto START,DATABASE_EDITOR


I get the following output on the console:





....note how the code is NOT printing the "One..." line, but it IS printing the "Two..." line.

This also takes me back to the main menu. If I CTRL-C at that point, and ask the console for PRINT Y, it gives it back as 2015, which it most certainly should not be.

Y can only ever be zero, one, two or three to satisfy the ON commands.

If I reflash MMBASIC 5.04.05 and load exactly the same code - no problems, everything works as it should.

Bizarre.

Y is apparently getting changed by something, but it does not get changed by earlier firmware, but the latest firmware DOES change Y somehow, some way.

BUT, if you put in some print statements, Y stays as it should, and the ON command works fine. Really scratching my head at this point....

I know WHY the ON command is passing right through to the database entries routine when you touch EXIT, because with Y being 2015 or so, it is taking the last of the routine labels it can find in the ON command, and hopping to there, but that should never happen, as when you touch the EXIT button, Y is set to 1, then the routine hops out of the loop, and runs the ON command. As Y is set to one, it runs the START routine, which takes it back to the main menu. As I say, all that was working just fine.

I will see if I can trim the program and produce a more condensed demo code.Edited by Grogster 2017-12-25
Smoke makes things work. When the smoke gets out, it stops!
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9610
Posted: 12:05am 24 Dec 2017
Copy link to clipboard 
Print this post

UPDATE:

Here is some demo code:





RESULTS:





The result is that "Two..." is printed, and "One..." is totally ignored.
Seems to be that the first line following the LOOP command, is being skipped?

EDIT: It's related to the EXIT DO command.

If I remove the If Inkey$<>"" Then Exit Do line, and change the LOOP line to read Loop Until Inkey$<>"", then the code works!








Therefore, in my original code posted above, the interpreter is not seeing or otherwise not executing the ON command at all(because it is right after the LOOP command) - and just starts running the next routine below it, which is the database editor routines....Edited by Grogster 2017-12-25
Smoke makes things work. When the smoke gets out, it stops!
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 12:39am 24 Dec 2017
Copy link to clipboard 
Print this post

Try with the exit do back in but put a dummy code line after the loop line.

Do
.
.
.
Exit do

Loop
x = x
print "one"

I don't have any mites upgraded yet.

Jim
VK7JH
MMedit
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9610
Posted: 12:45am 24 Dec 2017
Copy link to clipboard 
Print this post

Yes, that does work. I expect that Peter or Geoff will pick up on this and confirm it one way or the other.

If any other members have loaded 5.04.07, I would love to know if they are also getting the same result.
Smoke makes things work. When the smoke gets out, it stops!
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3292
Posted: 09:31am 24 Dec 2017
Copy link to clipboard 
Print this post

Drat. This is the season for adding bugs rather than removing them.
I can guess what is causing this. I will get onto it (probably Boxing Day).
Geoff Graham - http://geoffg.net
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9610
Posted: 12:35am 25 Dec 2017
Copy link to clipboard 
Print this post

No hurry - enjoy your Christmas!
I am just happy that this bug is confirmed. I can forget about this bug now, safe in the knowledge that it will be found and squished.
Smoke makes things work. When the smoke gets out, it stops!
 
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