# OPEN

Updated: 11/30/2021, 7:00:45 PM
Created: 11/30/2021, 7:00:45 PM
Last Updated By: Jake Tuttle
Read Time: 2 minute(s)

Tags: fileopen record handling file handling

# Description

The OPEN statement opens a file or device to a descriptor variable. It takes the general form:

OPEN{expression1,} expression2 TO {variable} {SETTING setvar} THEN|ELSE statements
1

Where:

  • The combination of expression1 and expression2 should evaluate to a valid file name of a file type that already installed on the jBASE system. If the file has a dictionary section to be opened by the statement then specify by the literal string "DICT" being specified in expression1.
  • If specified, the variable will be used to hold the descriptor for the file. It should then be used to access the file via READ and WRITE. If no file descriptor variable is supplied, then the file will be opened to the default file descriptor. Specific data sections of a multi level file may specified by separating the section name from the file name by a "," char in expression2.
  • If specifying the SETTING clause and the open fails, setvar will be set to one of these values.

If the OPEN statement fails it will execute any statements associated with an ELSE clause. If the OPEN is successful, it will execute any statements associated with a THEN clause. The syntax requires either one or both of the THEN and ELSE clauses.

The OPEN statement uses the environment variable JEDIFILEPATH to search for the named file. If there is no defined named file, it will search the current working directory followed by the home directory of the current process.

The file that is the subject of the OPEN statement can be of any type known to the jBASE system. Its type will be determined and correctly opened transparently to the application, which need not be aware of the file type. A jBASE BASIC program can open an unlimited amount of files.

An example of use is as:

OPEN "DICT", "CUSTOMERS" TO F.Dict.Customers ELSE
ABORT 201, "DICT CUSTOMERS"
END
1
2
3

to open the dictionary section of file CUSTOMERS to its own file descriptor F.Dict.Customers, or:

OPEN "CUSTOMERS" ELSE ABORT 201, "CUSTOMERS"
1

to open the CUSTOMERS file to the default file variable.

Go back to jBASE BASIC

Go back to Programmers' Reference Guide