Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 08:09 23 Jul 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 : Check for File existence on SD Card

Author Message
atmega8

Guru

Joined: 19/11/2013
Location: Germany
Posts: 724
Posted: 07:24am 19 Aug 2015
Copy link to clipboard 
Print this post

Hi,

how to Check for File existence on SD Card in MM+ ?

Any idea?

Thx
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3288
Posted: 08:12am 19 Aug 2015
Copy link to clipboard 
Print this post

Use OPTION ERROR thus:

Option ERROR CONTINUE
Open "MYFILE.EXT" For INPUT As #1
If MM.Errno = 0 Then
PRINT "File exists"
CLOSE #1
ELSE
PRINT "File does not exist"
CLOSE
Option ERROR ABORT

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

Guru

Joined: 19/11/2013
Location: Germany
Posts: 724
Posted: 10:28am 19 Aug 2015
Copy link to clipboard 
Print this post

Hello Geoff,

ah, the environment variable makes It possible, thats the trick

Thank you very much Geoff.
I can test this not before tomorrow evening, so one more Question:

Is it relevant to check mm.errno BEFORE closing the file handle with close #1 ?


Atmega8
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3288
Posted: 11:46am 19 Aug 2015
Copy link to clipboard 
Print this post

Yes, if you check it after closing the file it will report on the success (or not) of the close.
Geoff Graham - http://geoffg.net
 
MMAndy
Regular Member

Joined: 16/07/2015
Location: United States
Posts: 91
Posted: 07:47am 20 Aug 2015
Copy link to clipboard 
Print this post

Ok, I found OPTION ERROR CONTINUE/ABORT in the advanced MM+ manual.


I wish there was a similar command for the normal errors in MM+ so I could
make a GPIO scanner or OPTION LIST command for the Explore 64.
Edited by MMAndy 2015-08-21
 
kiiid

Guru

Joined: 11/05/2013
Location: United Kingdom
Posts: 671
Posted: 09:16am 20 Aug 2015
Copy link to clipboard 
Print this post

This actually reminds me to ask Geoff about the possibility for this idea:

How about by executing a certain command MMbasic checks the entire program for syntax or other errors? This is very useful in large programs with many branches where a bug might exist hidden within some rarely executing branch.
A compiler can easily pick these things during compilation, but with MMbasic such bugs can only be found when the program actually start executing the branch.
Basically this functionality only needs MMBasic to scan the whole program linearly without executing it, and verify that all keywords and subs/functions are known and defined, as well as the variables.
Does it sound like something possible?

Edited by kiiid 2015-08-21
http://rittle.org

--------------
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 4040
Posted: 11:07am 20 Aug 2015
Copy link to clipboard 
Print this post

I thought it already did that?!

Although... the recent ELSE END SUB posts suggests it has problems.

JohnEdited by JohnS 2015-08-21
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3288
Posted: 11:35pm 20 Aug 2015
Copy link to clipboard 
Print this post

  kiiid said  Basically this functionality only needs MMBasic to scan the whole program linearly without executing it, and verify that all keywords and subs/functions are known and defined, as well as the variables.
Does it sound like something possible?

That is an interesting idea and needs some thought... a bit like lint (for C). Correct keyword checking would be easy, less easy would be valid pin numbers, etc. Some other things like correct syntax for IF..THEN..ELSE could also be tricky.

I guess that about one fifth of MMBasic is error checking but it is still a difficult subject as there are so many errors that can be made and it is easy for the interpreter to stumble off into the darkness and produce some illogical response.

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

Guru

Joined: 11/05/2013
Location: United Kingdom
Posts: 671
Posted: 01:17am 21 Aug 2015
Copy link to clipboard 
Print this post

Thanks Geoff. I think it is worth the shot for a command like CHECK or VERIFY, something else like that, even if unable to pick every possible error in the beginning, but at least some of them.

Typical examples of mistakes (actually happened to me) may include a variable being defined as one type, but used as another, or mistyped function or variable names.

More advanced things like validity of pin numbers, structures, etc... maybe in the future. In order to get those, the interpreter will have to do speculative execution, without actually executing anything. That is a much more complex matter, still not impossible, but even without it such functionality can be very helpful in development.

http://rittle.org

--------------
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 4040
Posted: 01:35am 21 Aug 2015
Copy link to clipboard 
Print this post

It would be handy if the extra code to do it was in the PC version so flash isn't impacted - and besides it would be good to be able to thoroughly check the code before even sending across to a 'mite.

John
 
CircuitGizmos

Guru

Joined: 08/09/2011
Location: United States
Posts: 1427
Posted: 04:57am 21 Aug 2015
Copy link to clipboard 
Print this post

  JohnS said   It would be handy if the extra code to do it was in the PC version so flash isn't impacted - and besides it would be good to be able to thoroughly check the code before even sending across to a 'mite.

John


That.

A check in MMEdit would be spectacular. Perhaps it could be a call to an external program?
Micromites and Maximites! - Beginning Maximite
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6274
Posted: 11:56am 21 Aug 2015
Copy link to clipboard 
Print this post

Checking code on the PC without all the external hardware attached would be limited.

Using OPTION EXPLICIT helps catch typos.

MMEdit's format option helps catch misformed loops etc.

MMEdit's Variable report helps catch a few more potential errors.

I have often considered a code verifier in MMEdit but it would be difficult to keep up with the ever increasing number of versions of MM Basic.
MMEdit already has the ability to call an external program so if anyone is interested in providing the program...

Jim
VK7JH
MMedit
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 4040
Posted: 11:01pm 21 Aug 2015
Copy link to clipboard 
Print this post

I think speculative execution is rather more than was envisaged - which was to catch clearly wrong things like
ELSE END SUB

It might be useful for MMBasic to have a statement that a program can have (I suppose at the front) saying which kind of CPU(s) and features (I/O, min RAM size, MMBasic features - apply more thought here!) it uses so that an attempt to load it onto the wrong board can be instantly rejected with a useful error message. I'm thinking if it needs 2 SPIs and 3 UARTs (or whatever) and big arrays then it may be helpful for it to say so.

JohnEdited by JohnS 2015-08-23
 
kiiid

Guru

Joined: 11/05/2013
Location: United Kingdom
Posts: 671
Posted: 11:09pm 21 Aug 2015
Copy link to clipboard 
Print this post

  TassyJim said  
Using OPTION EXPLICIT helps catch typos.
Jim


In an interpreted environment such as MMbasic, OPTION EXPLICIT will catch something ONLY if the execution thread reach the bug. For example, if I have a loop for one million times with two branches, one executing 999999 times, and the other only once (imagine something serious - activating fire alarm for example), and my bug is hidden within the second one, it will remain hidden in 999999 times. That could be the difference between a product released with or without a bug in the software, and acting or not properly in a critical situation.


Edited by kiiid 2015-08-23
http://rittle.org

--------------
 
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