Reads data from the file associated with the specified file number, which was assigned to the file with the FileOpen function.
FileReadEx ( file#, blob )
FileReadEx ( file#, string )
Argument |
Description |
---|---|
file# |
The integer assigned to the file when it was opened. |
blob or string |
The name of the string or blob variable into which you want to read the data. |
Long. Returns the number of bytes read. If an end-of-file mark (EOF) is encountered before any characters are read, FileReadEx returns -100. If the file is opened in LineMode and a CR or LF is encountered before any characters are read, FileReadEx returns 0. If an error occurs, FileReadEx returns -1. FileReadEx returns -1 if you attempt to read from a string in stream mode or read from a blob in line mode. If any argument’s value is null, FileReadEx returns null.
FileReadEx returns long Unlike the FileRead function that it replaces, the FileReadEx function returns a long value.
If a file is opened in line mode, FileReadEx reads a line of the file until it encounters a CR, LF, or EOF. It stores the contents of the line in the specified variable, skips the line-end characters, and positions the file pointer at the beginning of the next line.
If the file was opened in stream mode, FileReadEx reads to the end of the file. FileReadEx begins reading at the file pointer, which is positioned at the beginning of the file when the file is opened for reading.
An end-of-file mark is a null character (ASCII value 0). Therefore, if the file being read contains null characters, FileReadEx stops reading at the first null character, interpreting it as the end of the file.
This example reads the file EMP_DATA.TXT into a string in line mode:
integer li_FileNum
string ls_Emp_Input
li_FileNum = FileOpen("C:\HR\EMP_DATA.TXT", &
LineMode!)
FileReadEx(li_FileNum, ls_Emp_Input)
END IF
This example reads the file EMP_PIC1.BMP and stores the data in the blob Emp_Id_Pic. The number of bytes read is stored in ll_bytes:
integer li_fnum
long ll_bytes
blob Emp_Id_Pic
li_fnum = FileOpen("C:\HR\EMP_PIC1.BMP", StreamMode!)
ll_bytes = FileReadEx(li_fnum, Emp_Id_Pic)