OPENSEQ |
![]() ![]() ![]() |
The OPENSEQ statement opens a record of a directory file for sequential access.
Format
OPENSEQ file.name, id {APPEND | OVERWRITE | READONLY} TO file.var {ON ERROR statement(s)} {LOCKED statement(s)} {THEN statement(s)} {ELSE statement(s)} or OPENSEQ pathname {APPEND | OVERWRITE | READONLY} TO file.var {ON ERROR statement(s)} {LOCKED statement(s)} {THEN statement(s)} {ELSE statement(s)}
where
At least one of the THEN and ELSE clauses must be present.
The named record is opened and associated with file.var for later operations.
The optional READONLY clause opens the item for read only access. Any attempt to write will fail.
Use of APPEND causes the OPENSEQ statement to position at the end of any existing data in the record such that subsequent write operations will append new data. Use of OVERWRITE truncates the record to remove any existing data.
If the record already exists, the THEN clause is executed. An update lock will be set on this record unless the record is read-only in which case a shared read lock is set.
If the record does not already exist, the ELSE clause is executed and the STATUS() function returns zero. The record will have been locked and use of WRITESEQ, WRITESEQF, WRITEBLK, WEOFSEQ or CREATE with the returned file.var will create the record. Alternatively, the lock can be released using RELEASE or closing the file.var
The ELSE clause is also executed if the specified item cannot be opened due to an error. The STATUS() function will contain the error code.
The LOCKED clause is executed if the record is already locked by another process.
The ON ERROR clause is executed if a fatal error occurs when opening the record. The STATUS() function will return an error code relating to the problem.
A record open for sequential access may be read and written using READSEQ and WRITESEQ respectively. The WRITESEQF statement provides a forced write and WEOFSEQ sets an end of file marker. The record should be closed using CLOSESEQ though it will be closed automatically when the program in which the file variable lies terminates.
The second form of OPENSEQ may be used to open a serial port by using the device name as pathname. On Windows, this name is COM1, COM2, etc. On other platforms, it is the device driver name.
Examples
OPENSEQ "STOCKS", "STOCK.LIST" TO STOCK.LIST ELSE IF STATUS() THEN ABORT "Cannot open stocks list" END
This program fragment opens the record STOCK.LIST of directory file STOCKS. If it fails to either open an existing record or to create a new record, the program aborts.
OPENSEQ "C:\TEMP\IMPORT.DATA" TO DAT.F ELSE IF STATUS() THEN ABORT "Cannot open import data file" END
This program fragment opens the operating system file in C:\TEMP\IMPORT.DATA for sequential processing.
See also: CLOSESEQ, NOBUF, READBLK, READCSV, READSEQ, SEEK, WEOFSEQ, WRITEBLK, WRITECSV, WRITESEQ, WRITESEQF |