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 | OFF directive specifies whether or not to suppress the automatic failure checking when using OPEN and CLOSE statements.


 Syntax:

 $FILETEST ON | 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: Creates and/or opens a file for reading and/or writing.

Opening Text Files


 Syntax:

 OPEN FileName$ FOR INPUT AS hFile

 Parameters:

  • FileName$ Name of a text file to create or open for reading.
  • hFile Name for a handle to the file.

 Syntax:

 OPEN FileName$ FOR OUTPUT AS hFile

 Parameters:

  • FileName$ Name of a text file to create or open for writing.
  • hFile Name of a handle to the file.

 Syntax:

 OPEN FileName$ FOR APPEND AS hFile

 Parameters:

  • FileName$ Name of an existing text file to open for appending.
  • hFile Name of a handle to the file.

Opening Binary Files


 Syntax:

 OPEN FileName$ FOR BINARY AS hFile

 Parameters:

  • FileName$ Name of an existing binary file to open for reading and writing.
  • hFile Name of a handle to the file.

 Syntax:

 OPEN FileName$ FOR BINARY NEW AS hFile

 Parameters:

  • FileName$ Name of an binary file to be created and opened for reading and writing. Note well, file contents will be lost if NEW is used to open an existing file.
  • hFile Name of a handle to the file.

 Syntax:

 OPEN FileName$ FOR BINARY INPUT AS hFile

 Parameters:

  • FileName$ Name of an existing binary file to be opened for reading.
  • hFile Name of a handle to the file.

 Syntax:

 OPEN FileName$ FOR BINARY APPEND AS hFile

 Parameters:

  • FileName$ Name of an existing binary file to be opened for writing.
  • hFile Name of a handle to the file.

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, which must be appended with % integer data type signifier, or an INTEGER literal. RecordSize, optionally, can be separated from RECLEN by an = sign, for example, RECLEN = 1024.

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

    If RecordSize is INTEGER variable(must be appended with % integer data type signifier) or a literal number, that integer must specify the fixed size of the random access record. RecordSize is calculated before the value is passed to RECLEN. The programmer is responsible for determining the fixed size of the record. RndAcc.bas is an example that shows how to open a file for random access reading.

Remarks:

Expressions such as:


 OPEN EXTRACT$(filename$,".") + ".bas" FOR INPUT AS fp1

are valid.

File Handles

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