BCX File Management Functions
FILELOCKED function
Purpose: FILELOCKED determines whether or not a file can be opened.
Syntax: RetVal% = FILELOCKED(FileName$) Parameters:
|
$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:
|
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:
|
Syntax: OPEN FileName$ FOR OUTPUT AS hFile Parameters:
|
Syntax: OPEN FileName$ FOR APPEND AS hFile Parameters:
|
Opening Binary Files
Syntax: OPEN FileName$ FOR BINARY AS hFile Parameters:
|
Syntax: OPEN FileName$ FOR BINARY NEW AS hFile Parameters:
|
Syntax: OPEN FileName$ FOR BINARY INPUT AS hFile Parameters:
|
Syntax: OPEN FileName$ FOR BINARY APPEND AS hFile Parameters:
|
Opening Random Access Files
Syntax: OPEN fName$ FOR BINARY [NEW] AS hFile RECLEN RecordSize Parameters:
|
Remarks:
Expressions such as:
OPEN EXTRACT$(filename$,".") + ".bas" FOR INPUT AS fp1
are valid.
File Handles
DIM MyFileHandle@ ' BCX Reserves @ for "C" FILE* data types OPEN "new.txt" FOR OUTPUT AS FP1 MyFileHandle@ = FP1 FPRINT MyFileHandle@, "This is a test" CLOSE FP1
OPEN "MYFILE.TXT" FOR INPUT AS FP1 PARSE(FP1) CLOSE FP1 FUNCTION PARSE(ABC AS FILE) LOCAL Buffer$ LINE INPUT ABC, Buffer$ FUNCTION = Buffer$ END FUNCTION
File handle variables are usually automatically dimensioned when the OPEN statement is used. The exception to this is when a file handle is explictly created to limit the scope to a subroutine or function as in this example
SUB FileTest() DIM RAW MyFP1 AS FILE OPEN "test.txt" FOR binary AS MyFP1 CLOSE MyFP1 END SUB
The file handle MyFP1 will be LOCAL in scope to the subroutine FileTest.
Note well that, when explictly dimensioning a DYNAMIC array of files, the data type must be specified as AS FILE PTR.
GLOBAL DYNAMIC FHandles[12] AS FILE PTR LOCAL DYNAMIC FHandles[12] AS FILE PTR
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
iOPEN
"PRN"
FOR
OUTPUT
AS
fp1FOR
i=
1
TO
60
"This is line number"
, iNEXT
CHR$
(
12
)
'CHR$(12) is Form Feed Character
CLOSE
fp1
BCX Console Sample Programs using OPEN function.