BCX File Management Functions

FILELOCKED function

Purpose: FILELOCKED determines whether or not a file can be opened.


Syntax:

 RetVal% = FILELOCKED(FileName$)

Parameters:

  • RetVal% Returns TRUE (1) if file cannot be opened, FALSE (0) if it can be opened.
  • FileName$ String literal or variable name of a file.

$FILETEST ON | OFF directive

Purpose: The $FILETEST ON or $FILETEST OFF directives specify whether or not to suppress the automatic failure checking when using OPEN and CLOSE statements.


Syntax:

 $FILETEST ON or $FILETEST OFF

Parameters:

  • ON specifies that automatic failure checking will occur when using OPEN and CLOSE statements.
  • OFF specifies that automatic failure checking will not occur when using OPEN and CLOSE statements.

OPEN statement

Purpose: The OPEN statement opens a file, specifies a streaming mode, and associates a file handle name with the file.


 OPEN filename FOR StreamingMode AS FileHandleName

filename can be a literal or variable string containing the name of the file with an absolute or relative path.

StreamingMode arguments INPUT, OUTPUT, APPEND, BINARY and NEW are outlined individually below.

The FileHandleName is used to identify the file in subsequent procedure calls, parameter arguments and other circumstances. QBASIC syle file handle names using the #number syntax are not supported in BCX. File handle names usually are automatically typed as a FILE handle, however, a file handle name can be explicitly created as a FILE handle. See the File Handle Names section remarks below for details.

Opening Text Files


Syntax:

 OPEN FileName$ FOR INPUT AS hFile

Streaming Mode: open text file for reading.

Parameters:

  • FileName$ Path to and name of the file to open.
  • hFile A file handle name.

Syntax:

 OPEN FileName$ FOR OUTPUT AS hFile

Streaming Mode: truncate contents of existing file to zero length or create text file for writing.

Parameters:

  • FileName$ Path to and name of the file to open.
  • hFile A file handle name.

Syntax:

 OPEN FileName$ FOR APPEND AS hFile

Streaming Mode: append; open or create text file for writing at end-of-file.

Parameters:

  • FileName$ Path to and name of the file to open.
  • hFile A file handle name.

Opening Binary Files


Syntax:

 OPEN FileName$ FOR BINARY AS hFile

Streaming Mode: open binary file for update (reading and writing).

Parameters:

  • FileName$ Path to and name of the file to open.
  • hFile A file handle name.

Syntax:

 OPEN FileName$ FOR BINARY NEW AS hFile

Streaming Mode: truncate contents of existing file to zero length or create binary file for update.

Parameters:

  • FileName$ Path to and name of the file to open.
  • hFile A file handle name.

Syntax:

 OPEN FileName$ FOR BINARY APPEND AS hFile

Streaming Mode: append; open or create binary file for update, writing at end-of-file.

Parameters:

  • FileName$ Path to and name of the file to open.
  • hFile A file handle name.

Syntax:

 OPEN FileName$ FOR BINARY INPUT AS hFile

Streaming Mode: open binary file for reading.

Parameters:

  • FileName$ Path to and name of the file to open.
  • hFile A file handle name.

Syntax:

 OPEN FileName$ FOR BINARY OUTPUT AS hFile

Streaming Mode: open binary file for update (reading and writing).

Parameters:

  • FileName$ Path to and name of the file to open.
  • hFile A file handle name.

Remarks:

Every OPEN statement must be terminated, eventually, with a CLOSE statement. See the CLOSE page for details.

Expressions such as:


 OPEN EXTRACT$(filename$,".") & ".bas" FOR INPUT AS FP1

are valid.

Opening Random Access Files


Syntax:

 OPEN fName$ FOR BINARY [NEW] AS hFile RECLEN RecordSize

Parameters:

  • fName$ Name of file to be opened.
  • NEW [OPTIONAL] Used if a new file is being created.
  • hFile Handle to the file.
  • RecordSize This can be a TYPE structure, an INTEGER variable, or an integer literal. RecordSize, optionally, can be separated from RECLEN by an = sign, for example, RECLEN = 1024.

Remarks:

If RecordSize is a TYPE structure, RECLEN will calculate automatically the size of the TYPE structure.

If RecordSize is an INTEGER variable or a literal number, that integer must specify the fixed size of the random access record.

If RecordSize is an INTEGER variable, it must be appended with % integer data type signifier.

RecordSize is calculated before the value is passed to RECLEN. The programmer is responsible for determining the fixed size of the record.

For more details see the Using Random Access Files.

File Handle Names

OPEN printer

OPEN is also used to send data to a printer. OPEN will make a connection to the printer using a handle to "PRN", the standard printer communications device. The data then is output to the printer using a PRINT statement. Here is a simple example for sending data to the default printer.


 DIM i
 
 OPEN "PRN" FOR OUTPUT AS FP1
 
 FOR i = 1 TO 60
   PRINT FP1,"This is line number", i
 NEXT
 
 PRINT FP1, CHR$(12)   'CHR$(12) is Form Feed Character

 CLOSE FP1
 

BCX Console Sample Programs using OPEN function.

S10.bas S82.bas S103.bas S113.bas S115.bas