# CREATE

Updated: 10/14/2021, 2:20:00 PM
Created: 10/14/2021, 2:20:00 PM
Last Updated By: mikes
Read Time: 1 minute(s)

# Description

This statement is intended to create files. It can be useful after an OPENSEQ statement to create a record in a directory file. CREATE creates the record or file if the OPENSEQ statement fails.

It takes the general form:

CREATE file.variable {THEN statements [ELSE statements] | ELSE statements}
1

If the record or file is created, it executes the THEN statements; if no record or file is created, it executes the ELSE statements.

An OPENSEQ statement for the specified file variable must be executed before the CREATE statement to associate the pathname or record ID of the file to be created with the file variable. If file.variable is null, the CREATE statement fails and the program enters the debugger.

# Note

CREATE statement may prove useful for exception handling, when OPENSEQ cannot find a record or file to open and the next operation is to be a READSEQ or READBLK. If the first file operation is a WRITESEQ, WRITESEQ creates the record or file if it does not exist.

In the following example, record_file2 does not yet exist. When OPENSEQ fails to open record_file2 in the TESTENV directory, the CREATE statement creates and opens it to the file variable FILE, ready to be written to.

INCLUDE JBC.h
OPENSEQ 'TESTENV' : DIR_DELIM_CH : 'record_file2' TO FILE ELSE
    CREATE FILE ELSE ABORT
END

WEOFSEQ FILE
WRITESEQ 'I am a test record' TO FILE ELSE
    CRT 'Failed to write'
END
1
2
3
4
5
6
7
8
9

# Warning

OPENSEQ will automatically create the target file if openseq_creates = true is present (in Config_EMULATE).
You can verify this by running config-strings.

Go back to jBASE BASIC

Go back to Programmers' Reference Guide