Welcome to jBASE's new documentation site! Many answers to your questions can be found by searching the Knowledgebase or viewing the jBASE Documentation. We also have a Google Group for peer discussion about jBASE. If you are unable to find the information you are looking for, jBASE Support will be glad to assist in resolving your technical problems. Enjoy and please provide comments and feedback .

How can we help you?

SEEK

Description

The SEEK statement is used to move the file pointer by an offset specified in bytes, relative to the current position, the beginning of the file, or the end of the file.

The statement takes the general form: 

SEEK file.variable [ , offset [ , relto] ] 
{THEN statements [ELSE statements] | ELSE statements}

Where:

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.

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.

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: 

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).

The following example reads and prints the first line of. 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


See also: OPENSEQ, READSEQ, and WRITESEQ statements.

Go back to jBASE BASIC.

Was this article helpful?