Home Why Omnibasic Features FAQ Examples
Reviews Keyword/Syntax On-Line Manual Download Manual ScreenShots

Chapter 5

File Handling

There are two methods of doing file handling. The path method and the ANSI stream method. Then ANSI stream file I/O method is an optional method. For purposes of explanation, we will refer to the “old” way of doing files as “path” and the ANSI way as “stream”. The two styles CANNOT be mixed. The stream method will internally use the C functions fopen (), fread ( ), etc., to be used instead of open ( ), read ( ), etc. This was implemented to speed up file I/O on certain systems. For most, it is of no concern. Stream I/O is supported in the following statements and functions:

  1. create
  2. open
  3. close
  4. get
  5. put
  6. read
  7. write
  8. seek
  9. eof ( )
  10. filsiz ( )
  11. filpos ( )

Stream I/O is NOT supported for the following:

  1. print
  2. input
  3. fprint
  4. finput

These examples illustrate the usage:

Path Stream
DIM FileNum: BYTE DIM FilePtr: FILE
DIM X:Long DIM X:Long
X = 1234 X = 1234
CREATE #FileNum, “test” : WRITE CREATE FilePtr, “test” : WRITE
WRITE #FileNum, X WRITE FilePtr, X
CLOSE #FileNum CLOSE FilePtr
OPEN #FileNum, “test”: UPDATE OPEN FilePtr, “test”: UPDATE
READ #FileNum, X READ FilePtr, X
SEEK #FileNum, 0 SEEK FilePtr, 0
PRINT FILPOS ( #FileNum) PRINT FILEPOS (FileNum)
CLOSE #FileNum CLOSE FilePtr

As you can see, the main difference in the usage is the “#” prefix to the path number variable. Not apparent from this example is the fact that you cannot assign a value to a FILE variable in an assignment statement. For example:

FilePtr = 3

will cause an error to be reported. While these two methods are radically different internally, OmniBasic has made the use of either to appear very similar.

Also note that with stream I/O, creating a file that already exists will not cause an error as in path I/O, but rather will delete the old file and start a new one with the same name.

Next Page: Chapter 6
Table of Contents


Home || Why Omnibasic || Features || FAQ || Examples
Reviews || Links || Privacy Statement || Top of Page

 

   Innomation Systems, Inc.

117 Morrison Ave. Morrison, MO 65061 (573) 294-6130

OmniBasic is a trademark of Innomation Systems, Inc., other trademarks are the property of their respective owners.
Innomation Systems, Inc. reserves the right to change prices and specifications without prior notice.
Copyright © 2000, 2001, 2002 Innomation Systems, Inc.