Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 20:04 13 Nov 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 : MMbasic Interpreter bug? [with OPTION DEFAULT]

Author Message
MustardMan

Senior Member

Joined: 30/08/2019
Location: Australia
Posts: 175
Posted: 09:56pm 21 Apr 2020
Copy link to clipboard 
Print this post

Hi,

When using OPTION DEFAULT NONE to enforce good programming habits (everything must be properly defined), I get an error with EXIT FOR. I have attached the relevant code snippet below:


OPTION EXPLICIT        ' All varibles must be explicitly defined before use
OPTION DEFAULT NONE    ' And all variables must have their type explicitly defined too

CONST params = 16      ' It seems constants can't have their type specified (??)

DIM INTEGER n          ' General use


       FOR n = params TO 1 STEP -1          ' Check backwards: no touch results in n=0
         IF CheckPress(n) THEN EXIT FOR     ' Exit FOR loop early if a touch is detected
       NEXT n                               ' n = index (0 = no touch, or touch in wrong area)


The "button" check is done backwards resulting in a non-button area touch being zero. This is easier to deal with (in a program) than checking for '= params+1' or '> params'.

The error thrown is:
[119] If CheckPress(n) Then Exit For
Error: Variable type not specified

If I comment out the OPTION DEFAULT line, it works fine.

Interpreter version output with "? MM.VER" is 5.0502, and it is running on a MicroMite Explore 100.

As a side note, I was not able to define the type of a constant (tried AS INTEGER, INTEGER, before, after, used DIM, no luck). Can I not define the type of a constant?

Cheers,
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3308
Posted: 10:54pm 21 Apr 2020
Copy link to clipboard 
Print this post

I could not get this to fail (Ver 5.05.02).  Perhaps there is something going wrong in the function CheckPress() that is causing MMBasic to report an error in the wrong place.

This is the test code that I used:
OPTION EXPLICIT        ' All varibles must be explicitly defined before use
OPTION DEFAULT NONE    ' And all variables must have their type explicitly defined too
CONST params = 16      ' It seems constants can't have their type specified (??)
DIM INTEGER n          ' General use

      FOR n = params TO 1 STEP -1          ' Check backwards: no touch results in n=0
        IF CheckPress(n) THEN EXIT FOR     ' Exit FOR loop early if a touch is detected
      NEXT n  
 
  Function CheckPress(a as integer) as integer
    CheckPress = 0
  End Function


On your second point.  Yes, you are supposed to be able to specify the type of a constant.  But doing that caused an error in your test code.  I will add this to the bug list for the next version.

Geoff
Geoff Graham - http://geoffg.net
 
Turbo46

Guru

Joined: 24/12/2017
Location: Australia
Posts: 1646
Posted: 11:20pm 21 Apr 2020
Copy link to clipboard 
Print this post

Geoff, I quickly tried MustardMan's program and it failed because CheckPress was not specified.

It says several times in the manual that a CONST defaults to the implied data type:

  Quote  When a constant number is used it will be assumed that it is an integer if a decimal point or exponent is not used. For example, 1234 will be interpreted as an integer and 1234.0 will be interpreted as a floating point number. String constants are always surrounded by double quote marks (eg, "text string").


  Quote  The identifier can have a type suffix (!, %, or $) but it is not required.


So for that reason I thought it is not necessary to specify the type of a constant?

Bill
Keep safe. Live long and prosper.
 
MustardMan

Senior Member

Joined: 30/08/2019
Location: Australia
Posts: 175
Posted: 02:49am 22 Apr 2020
Copy link to clipboard 
Print this post

@Turbo46
My apologies, I will post more of the program this-evening when I get home. I suppose thinking there might be a bug does call for a bit more than a tiny snippet of code! As Geoffg has pointed out, it may well be the definition of "CheckPress()" that is my problem.

I did read in the manual that constants were typed by the value that they were given, which is fine, and really easy. Coming from a C background where things are much 'tighter', I did not think of trying symbols when specifying a constant. I instinctively thought to "word" it (eg: FLOAT) rather than "symbolise" it (eg: $) to make it something in particular.


Cheers,
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3308
Posted: 03:14am 22 Apr 2020
Copy link to clipboard 
Print this post

I have since checked the manual and it does indeed support the current behaviour.  However, to me it would be more consistent if CONST supported full typing like DIM.  From memory that part of the code was complex and maybe that is why full typing did did not make it in.

Anyway, I will investigate.

Geoff
Geoff Graham - http://geoffg.net
 
Turbo46

Guru

Joined: 24/12/2017
Location: Australia
Posts: 1646
Posted: 03:17am 22 Apr 2020
Copy link to clipboard 
Print this post

I'm sorry too MustardMan. I assumed that your snippet was expected to show the problem as was. Geoff knew better on both points of course. I was writing my post when his popped up. I probably should have deleted the contents and shut up.

Bill

PS. It happened again!
Keep safe. Live long and prosper.
 
MustardMan

Senior Member

Joined: 30/08/2019
Location: Australia
Posts: 175
Posted: 10:38am 22 Apr 2020
Copy link to clipboard 
Print this post

@Turbo46 and @Geoffg

Well, I do feel stupid - Geoff was spot on with his diagnosis, it was the definition of 'CheckPress()'.

The original:
FUNCTION CheckPress (n AS INTEGER)
LOCAL INTEGER x = TOUCH(x)
LOCAL INTEGER y = TOUCH(y)
blah blah


And the way it should be, and working...
FUNCTION CheckPress (n AS INTEGER) AS INTEGER
LOCAL INTEGER x = TOUCH(x)
LOCAL INTEGER y = TOUCH(y)
blah blah


With regard to constants: it is not an issue, I just wondered if it was supposed to support word definitions or not, and 'not' it is!

Cheers, and many thanks!!!
 
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