FOPEN
Open the specified file in accordance with the specified access mode.
WebVue support - Yes.
Before using any of the file management instructions, except FSTAT, RENAME, UNLINK, FILETOBUF or BUFTOFILE, you must first open the file using an FOPEN instruction.
Before any program including the FOPEN instruction ends, it must execute an FCLOSE instruction.
Syntax
IntVal = FOPEN(Filename, Access);
Return type: INTEGER.
Argument |
Meaning |
Filename |
The name of the file to be opened. Type STR. |
Access |
The access mode for the open function. Type STR. |
r |
Open a text file for read. |
w |
Create a text file and open it for write. Overwrites an existing file of the same name. |
a |
Open an existing file for write, and append to the end. |
r+ |
Open a text file for both read and write. |
w+ |
Create a text file and open it for read and write. Overwrites an existing file of the same name. |
a+ |
Open an existing file for read, write and append to the end. |
b |
Open a file in a binary mode. |
Execution
A file is opened with the given access mode.
Return: |
1 if successful, else 0. |
Any files opened by SCADA BASIC must reside in the project folder TP.
It is essential to check the return flag each time a file is opened as attempting to read from a file that has not been opened successfully may cause a fatal error.
When the file is in text mode the LF character is transformed into CRLF in the file.
Example
The default folder is Project\TP Folder
'write file histo.fil in the TP folder
i1 = FOPEN("histo.fil","w+");
'read file in the C:\Test folder
i1 = FOPEN("C:\\TEST\\histo.fil","r");