Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 06:52 05 May 2024 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 : Divide by zero when using dir$()

Author Message
Bizzie
Senior Member

Joined: 06/07/2014
Location: Australia
Posts: 185
Posted: 10:43pm 24 Apr 2017
Copy link to clipboard 
Print this post

Hi all,

Just came across the following:-


? mm.ver
5.0302
> ? mm.device$
Micromite Plus
> list


If files$ = "" Then
Print "No files found"
EndIf

f$=Dir$("*.*",FILE)
Do While f$ <> ""
Print f$
f$ = Dir$()
Loop
> run
No files found


CPU exception #13 (possible divide by zero) at address 0x9D01BBA0
Processor restarted

>
>


Obvious I suppose but will really toss many.
Most of the code above is from the DIR$() example on page 46 of the plus manual.

What is the best way to handle this situation? That is a new or blank SD card with no files.

I will test files$ first to see if it is blank (hence my first if statement) and then if not recurs through the files.

I think it really needs pointing out in the manual as divide by zero is not at all obvious to most.

EDIT: Just realised my first if statement seems to work but for the wrong reasons.
Ignore these comments.Edited by Bizzie 2017-04-26
Rob White
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3165
Posted: 01:00am 25 Apr 2017
Copy link to clipboard 
Print this post

Any CPU exception is not good and should never happen.
I will have a look at it tomorrow and see what is going on.

Geoff
Geoff Graham - http://geoffg.net
 
Bizzie
Senior Member

Joined: 06/07/2014
Location: Australia
Posts: 185
Posted: 12:21pm 25 Apr 2017
Copy link to clipboard 
Print this post

Thanks Geoff,

I have not got much time this morning. I will try another board as I just changed SD cards and got different results! - That is SD card not present.

Regards

Rob White
 
Bizzie
Senior Member

Joined: 06/07/2014
Location: Australia
Posts: 185
Posted: 10:51pm 25 Apr 2017
Copy link to clipboard 
Print this post

Geoff,

Afraid this was yet another case of "finger trouble"!

I disabled the SD card and then did another option sdcard 24 (SD card on display) and all was fine. I can not tell you if option list indicated 24 or not.


Rob White
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3165
Posted: 12:37am 26 Apr 2017
Copy link to clipboard 
Print this post

Yes, I just tested it and no exception. Phew!!
Geoff Graham - http://geoffg.net
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024