I'm currently working on a program to calculate and draw the most efficient use of expensive fabric. It a kind of simple database where I need to access directories and work with directories.
Is it in simple ways possible to emulate the following commands like: MKDIR, CHDIR and RMDIR
DIM filename$(999)
count = 0
PROClistdirectory
FOR list = 1 TO count
PRINT filename$(list)
NEXT list
END
DEF PROClistdirectory
LOCAL dir%, sh%, res%
DIM dir% LOCAL 317
SYS "FindFirstFile", "*.BBC", dir% TO sh%
IF sh% <> -1 THEN
REPEAT
count += 1 :REM added to original example
REM PRINT $$(dir%+44)
filename$(count) = $$(dir%+44)
SYS "FindNextFile", sh%, dir% TO res% :REM added to original example
UNTIL res% = 0
SYS "FindClose", sh%
ENDIF
ENDPROC
BBC Model B - 1984-1989. 6502 assembler, Unicomal 1988-1994, Some C and C++, Pascal 1990-1994. Bought a copy of BBC-BASIC 2007, but started to program at a daily basis 2019. C++ in 2021.
These functions are available via star commands:
*MKDIR (or *MD)
*CHDIR (or *CD)
*RMDIR (or *RD)
If you use the star commands directly you need to define the target directory explicitly but you can use OSCLI to "wrap" the star commands, together with a variable directory name, for example
OSCLI "CD """+directory$+""""
would change to the directory defined in directory$. Note the use of triple quotes to include a quote in the string!
This is covered in more detail in the manual. Hope that helps.
As I recall back in eighties did UniComal have an errorhandler, that was very nice to use.
TRAP
some error prone code (eg MKDIR existing name)
HANDLER
PRINT "Directory name exist!"
RETRY
ENDTRAP
Is it possible to do similar error handling in BBCBASIC?
Best regards,
Ivan
BBC Model B - 1984-1989. 6502 assembler, Unicomal 1988-1994, Some C and C++, Pascal 1990-1994. Bought a copy of BBC-BASIC 2007, but started to program at a daily basis 2019. C++ in 2021.
oops = FALSE
ON ERROR LOCAL IF FALSE THEN
CASE oops OF
WHEN FALSE
PRINT "2/0 ";2/0
WHEN TRUE
PRINT "I'm back!"
OTHERWISE
PRINT "What?"
ENDCASE
ELSE
CASE ERR OF
WHEN 18:
oops = TRUE
PRINT "I'll be back"
OTHERWISE RESTORE ERROR : ERROR ERR, REPORT$
ENDCASE
ENDIF : RESTORE ERROR
You do not have the required permissions to view the files attached to this post.
BBC Model B - 1984-1989. 6502 assembler, Unicomal 1988-1994, Some C and C++, Pascal 1990-1994. Bought a copy of BBC-BASIC 2007, but started to program at a daily basis 2019. C++ in 2021.
Ivan wrote: ↑Sat 06 Jun 2020, 11:50
I am trying to do the same in BBCBASIC, but I think I don't understand the concept..?
The Wiki article I linked to describes the BBC BASIC equivalent of the conventional TRY...CATCH style of Structured Exception Handling (e.g. as used in C++), which does not support a RETRY statement, or anything similar as far as I know. I wonder if RETRY is really what you want here, but if it is I would suggest that you simply roll-your-own equivalent using ON ERROR LOCAL rather than going down the SEH route: