REWIND moves the read/write pointer of a file to the beginning of the file without the need to close and then re-open the file.
Syntax:REWIND(FileHandle AS FILE) Parameters:
|
DIM A_Line$ OPEN "Test.txt" FOR OUTPUT AS FP0 FPRINT FP0, "This is the first line of Test.txt." FPRINT FP0, "This is the second line of Test.txt." FPRINT FP0, "This is the third line of Test.txt." FPRINT FP0, "This is the fourth line of Test.txt." CLOSE FP0 OPEN "Test.txt" FOR INPUT AS FP1 A_Line$ = LOOKAHEAD$(FP1, 0) PRINT A_Line$ FOR INTEGER j = 1 TO 4 LINE INPUT FP1, A_Line$ PRINT A_Line$ NEXT ? PRINT "Again, from the beginning !" REWIND(FP1) '<<< Reset File Pointer LINE INPUT FP1, A_Line$ ? PRINT A_Line$ A_Line$ = LOOKAHEAD$(FP1, 3) PRINT A_Line$ CLOSE FP1 PAUSE
This is the first line of Test.txt. This is the second line of Test.txt. This is the third line of Test.txt. This is the fourth line of Test.txt. Again, from the beginning ! This is the first line of Test.txt. This is the fourth line of Test.txt. Press any key to continue . . .
LOOKAHEAD$ will return the next, or an optionally specified, line of text from an open file stream without permanently changing the current line pointer.
Syntax:A_Line = LOOKAHEAD$(FileHandle AS FILE, [, LineToRead AS INTEGER]) Return Value:
Parameters:
|
OPEN "Test.txt" FOR OUTPUT AS FP1 FPRINT FP1, "This is the first line of Test.txt." FPRINT FP1, "This is the second line of Test.txt." FPRINT FP1, "This is the third line of Test.txt." FPRINT FP1, "This is the fourth line of Test.txt." CLOSE FP1 OPEN "Test.txt" FOR INPUT AS FP1 PRINT LOOKAHEAD$(FP1, 4) PRINT LOOKAHEAD$(FP1, 3) PRINT LOOKAHEAD$(FP1, 2) PRINT LOOKAHEAD$(FP1, 1) CLOSE FP1 KILL "Test.txt" PAUSE
This is the fourth line of Test.txt. This is the third line of Test.txt. This is the second line of Test.txt. This is the first line of Test.txt. Press any key to continue . . .