home *** CD-ROM | disk | FTP | other *** search
- FUNCTION PForKey$(Msg$)
- 'Waits for a keystroke and returns value to caller.
- PRINT Msg$, "Press any key to continue..."
- PRINT
- WHILE NOT INSTAT:WEND
- PForKey$ = INKEY$
- END FUNCTION
-
- SUB SequentialOutput
- 'The file is opened for sequential output,
- 'and some data is written to it.
- KeyP$ = PForKey$("Now for some sequetial output")
- OPEN "OPEN.DTA" FOR OUTPUT AS #1
- IntegerVar% = 12345
- TempStr$ = "History is made at night."
- WRITE #1, TempStr$, IntegerVar% * 2, TempStr$, IntegerVar% \ 2
- CLOSE 1
- END SUB
-
- SUB SequentialAppend
- 'The file is opened for sequential output, and
- 'data in this case is added to the end of file.
- KeyP$ = PForKey$("Now to append some more stuff")
- OPEN "OPEN.DTA" FOR APPEND AS #1
- IntegerVar% = 32123
- TempStr$ = "I am not a number!"
- WRITE #1, TempStr$, IntegerVar% * 0.2
- CLOSE 1
- END SUB
-
- SUB SequentialInput
- 'The file is opened for sequential input,
- 'and data read is displayed onscreen
- KeyP$ = PForKey$("Now to read it back" )
- OPEN "OPEN.DTA" FOR INPUT AS #1
- LINE INPUT #1, TempStr$
- PRINT TempStr$
- PRINT
- TempStr$ = ""
- WHILE NOT EOF(1)
- TempStr$ = TempStr$ + INPUT$(1,1)
- WEND
- PRINT TempStr$
- PRINT
- CLOSE 1
- KeyP$ = PForKey$("")
- END SUB
-
- SUB BinaryIO
- 'The file is opened for Binary I/O. Data is read using
- 'GET$. SEEK explicitly moves the file pointer to the end
- 'of file, and the same data is written back to the file.
- KeyP$ = PForKey$("Now for Binary input and output" )
- OPEN "OPEN.DTA" FOR BINARY AS #1
- TempStr$ = ""
- WHILE NOT EOF(1)
- GET$ 1,1,Char$
- TempStr$ = TempStr$ + Char$
- WEND
- PRINT TempStr$
- PRINT
- SEEK 1, LOF(1)
- FOR I% = 1 TO LEN( TempStr$ )
- PUT$ 1, MID$( TempStr$, I%, 1 )
- NEXT I%
- CLOSE 1
- KeyP$ = PForKey$("")
- END SUB
-
- SUB RandomIO
- 'Open file for random I/O. Use MAP to declare a buffer to
- 'hold the data that is written and read. GET and PUT read
- 'and write the data. Note that before GET is performed, the
- 'data to be stored in the file's buffer is assigned to the
- 'MAPped flex string variable.
- KeyP$ = PForKey$("Now for some random I/O" )
- OPEN "OPEN.DTA" AS #1 LEN = 1
- MAP 1,1 AS Char$$
- TempStr$ = ""
- TempSize% = LOF(1)
- 'using GET, read in the entire file
- FOR I% = 1 to TempSize%
- GET 1, I%
- TempStr$ = TempStr$ + Char$$
- NEXT I%
- 'PUT copies the data in reverse into the random-access file.
- FOR I% = LEN( TempStr$ ) TO 1 STEP -1
- Char$$ = MID$(TempStr$, I%, 1 )
- PUT 1, LOF(1)
- NEXT I%
- CLOSE 1
- END SUB
-
- CLS
- CALL SequentialOutput
- CALL SequentialAppend
- CALL SequentialInput
- CALL BinaryIO
- CALL RandomIO
- END