FB II Compiler

PG PRO

Debugging

Memory

System

Mathematics

Resources

Disk I/O

Windows

Controls

Menus

Mouse

Keyboard

Text

Fonts

Drawing

Sound

Clipboard

Printing

Communication

ASM

Made with FB

DISK I/O

Handle disk errors


After a lot of testing in trying to find this out myself, I managed to get a solid routine working that I use for my programs prefs (and it handles any disk errors, like file not found). I snipped the two functions that do the magic and you can read the comments to see where things go before and after.
LOCAL FN HandleDiskError:'          handles the disk errors we can encounter
  SELECT ERROR AND 255:'                      mask out the error code itself
    CASE _fileNotFound
      FN LoadDefaultPrefs:'                           load the default prefs
      OSErr=FN fndPrefFile(prefVol):'     find the preferences volume for us
      FN PrefsWrite:'                               go create the prefs file
  END SELECT
  ERROR=_noErr:'                                   reset the error condition
END FN
'
LOCAL FN PrefsRead
  ON ERROR GOSUB 65535:'                          enable our own error testing
  ON ERROR FN HandleDiskError:'       use my routine for handling a disk error
  DEF OPEN "PrefWPRO":'                                       type and creator
  OPEN "I",#1,prefsName$,,prefVol:'                         read our pref file
  fileSize=LOF(1,1):'                               get the file size in bytes
  LONG IF fileSize<>_prefSize:'      did we change the size of the prefs file?
    CLOSE #1:'                                              close the file now
    FN LoadDefaultPrefs:'                               load the default prefs
    OSErr=FN fndPrefFile(prefVol):'         find the preferences volume for us
    FN PrefsWrite:'                                   go create the prefs file
    OPEN "I",#1,prefsName$,,prefVol:'                       read our pref file
  END IF
  READ FILE #1,@ListWindow,varPrefSize:'             read in  simple variables
  READ FILE #1,@appStrings&(0),76:'                           read this in now
  READ FILE #1,@monthTime&(0),52:'                       and then read this in
  CLOSE #1:'                          it resumes here from the error condition
  ON ERROR RETURN:'                                turn off the error checking
END FN
Mel Patrick