Purpose |
Return the end-of-file status of an opened file or TCP/UDP transmission. |
Syntax |
y = EOF(filenum&) |
Remarks |
Use EOF to determine when the end of a file has been reached while reading its data. filenum& is the file number specified when the file was Opened. EOF returns -1 (TRUE) if the end of the specified file has been reached, or if an error occurs trying to check for the end of the file. Otherwise, EOF returns 0 (FALSE). If filenum& is not a valid, open file, a run-time Error 53 will occur ("File not found"). If filenum& is for a binary file, EOF returns TRUE only if the most recent file operation was a read operation, and that operation could not read the requested number of bytes. The EOF function may also be used with the COMM LINE and TCP LINE statements to detect that an incomplete line was received. Normally, these statements read data until a $CRLF character pair is found, and in that case, EOF will return 0 (FALSE). However, even if no $CRLF has been found, the statements will end when no additional data is available. In that case, they will return whatever data has already been accumulated, and set EOF to -1 (TRUE). In many cases, it would be prudent to test EOF after every COMM LINE and TCP LINE to verify that a full line has been received. In some cases, you may wish to execute the statement one or more additional times, combining the data, in order to obtain a full line of text. |
See also |
|
Example |
' Open an ASCII text file and read it hFile = FREEFILE OPEN "TEXTFILE.TXT" FOR INPUT AS hFile WHILE ISFALSE EOF(hFile) LINE INPUT# hFile, x$ WEND CLOSE hFile |