• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

I/O errors

Because so much about accessing external files is not directly under your control, errors are a lot more common when you use FileIO than when you use standard Lingo. A file you want to create may already exist; the file you want to write to may be read-only—an almost endless list of things can go wrong. Although so far in this book we haven't been doing it (to keep things simple), it's a good idea for you to check after each FileIO command to see whether an error occurred—and if an error did occur, you should have a handler on hand to take care of the problem. If the user specifies a file and the file can't be opened, for example, you should be ready to prompt the user to name a different file.

The FileIO Xtra includes the status command that you can use to make sure that things are working correctly. The status command returns a code referring to the last command executed. If status returns 0, you know that no error occurred. Otherwise, something went wrong. You should include a handler in your code that you call whenever something doesn't work (use a case statement that uses the returned error code to determine what to do). For your own information, or to display an error message to the user, you can use FileIO's error command, which returns a string describing the error. Here's how that might look in the Message window:


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint