FILETOBUF
Create a memory buffer using the contents of an ASCII file.
WebVue support - Yes.
Syntax 1
LongVal = FILETOBUF(Filename);
Return type: LONG.
Argument |
Meaning |
Filename |
The name of the file from which the buffer is to be created.
Type STR. |
Execution
A buffer is created in memory and the handle (start address) is returned by the function. The buffer size is automatically allocated using the size of the file.
Return: The handle of the buffer if successful, else 0.
Syntax 2
LongVal = FILETOBUF(Filename, Size);
Argument |
Meaning |
Filename |
The name of the file from which the buffer is to be created.
Type STR. |
Size |
The size of the buffer to be created. Any numeric type. |
Return type: LONG.
Execution
A buffer is created in memory and the handle (start address) is returned by the function. The buffer size is fixed at the specified size. If the file is larger than the maximum permitted size of a buffer (see the note below) then the buffer is not created.
Return: The handle of the buffer if successful, else 0 (file larger than Size).
The default folder for relative file names is the project
folder \TP.
It is unnecessary to use the ALLOC_BUFFER instruction prior to using FILETOBUF as the buffer space
is automatically allocated, but FREE_BUFFER must be used to free the buffer space once it is no longer required to keep it in memory.
Example
'This program uses the file UTIL.TXT in the project TP folder
SUB Main()
DIM StrFilename as Str;
DIM strLine as Str;
DIM lngBuffer as Long;
StrFilename = "util.txt"; 'File name
lngBuffer = FILETOBUF(StrFilename);'The test file must exist
strLine = CGET_BUFFER (lngBuffer,0,20); 'Print the first 20 characters
FREE_BUFFER(lngBuffer );
PRINT(strLine);
END SUB