![]() ![]() |
|
SEEKThe SEEK statement moves a file pointer by an offset specified in bytes, relative to the current position, the beginning of the file, or the end of the file.
COMMAND SYNTAXSEEK file.variable [ , offset [ , relto] ] {THEN statements [ELSE statements] | ELSE statements} file.variable specifies a file previously opened for sequential access. offset is the number of bytes before or after the reference position. A negative offset results in the pointer being moved before the position specified by relto. If offset is not specified, 0 is assumed. NOTE: On Windows NT systems, line endings in files are denoted by the character sequence RETURN + LINEFEED rather than the single LINEFEED used in UNIX files. The value of offset should take into account this extra byte on each line in Windows NT file systems. The permissible values of relto and their meanings follow: 0 Relative to the beginning of the file 1 Relative to the current position 2 Relative to the end of the file If relto is not specified, 0 is assumed. If the pointer is moved, the THEN statements are executed and the ELSE statements are ignored. If the THEN statements are not specified, program execution continues with the next statement. If the file cannot be accessed or does not exist the ELSE statements are executed; any THEN statements are ignored. If file.variable, offset, or relto evaluates to null, the SEEK statement fails and the program terminates with a run-time error message. Note: On Windows NT systems, if you use the OPENDEV statement to open a 1/4-inch cartridge tape (60 MB or 150 MB) for sequential processing, you can move the file pointer only to the beginning or the end of the data. For diskette drives, you can move the file pointer only to the start of the data.Seeking beyond the end of the file and then writing creates a gap, or hole, in the file. This hole occupies no physical space, and reads from this part of the file return as ASCII CHAR 0 (neither the number nor the character 0). For more information about sequential file processing, See also: OPENSEQ, READSEQ, and WRITESEQ statements.
EXAMPLE The following example reads and prints the first line of RECORD4. Then the SEEK statement moves the pointer five bytes from the front of the file, then reads and prints the rest of the current line. OPENSEQ '.', 'MYSEQFILE' TO FILE ELSE ABORT READSEQ B FROM FILE THEN PRINT B SEEK FILE,5, 0 THEN READSEQ A FROM FILE THEN PRINT A ELSE ABORT END The output of this program is: FIRST LINE LINE |