IO_STATUS(file_id)
Return an INTEGER value indicating the success or type of failure of the last operation on the file argument
CLR_IO_STATUS(file_id)
Clear the results of the last operation on the file argument
in all of the program examples i find in the Karel manual whenever IO_STATUS is used it is immediately followed by CLR_IO_STATUS. This does not seem to be needed. i put together a quick test and it read out as follows.
open MC:\IO.csv failed
2014
UD1:\IO.csv opened
0
To me this means that the CLR_IO_STATUS is not needed as the value will be replaced by the next operation that uses it. the CLOSE FILE built in always sets it to zero. my favorite part is that 2014 is not a listed code in the table. i would expect either 12327 Open file failed or 12328 file is not opened.
PROGRAM fileopentest
%NOLOCKGROUP
VAR
STATUS, entry :INTEGER
devicePath :STRING[64]
inputFile :FILE
BEGIN
GET_VAR(entry,'*SYSTEM*','$DEVICE',devicePath,STATUS) -- path was set to wrong location for this test MC:\IO.csv does not exist. file is saved at UD1:\IO.csv
-- FILE_LIST('IO.csv', n_skip, format, ary_nam, n_files, status)
devicePath = devicePath + '\IO.csv'
OPEN FILE inputFile ('RO',devicePath)
IF (IO_STATUS(inputFile) <> 0 ) THEN
-- CLR_IO_STAT(inputFile)
WRITE('open ', devicePath, ' failed',CR)
WRITE(IO_STATUS(inputFile),CR) -- returns
CLOSE FILE inputFile -- sets IO_STATUS back to zero by default
devicePath = 'UD1:\IO.csv' -- set path to correct location
OPEN FILE inputFile ('RO',devicePath)
WRITE(devicePath, ' opened',CR)
WRITE(IO_STATUS(inputFile),CR)
ELSE
WRITE(devicePath, ' opened',CR)
ENDIF
END fileopentest
Display More