Reads a file. (version 4.48 or later)
fileread <file handle> <read byte> <strvar>
Reads specified byte data from the file specified by <file handle>.
The data are written into the string variable <strvar>. The file pointer is moved to reading bytes.
If the file pointer reaches the end of the file while reading the data, the system variable "result" is set to 1. Otherwise, "result" is set to zero.
The range of <read byte> argument must be from 1 to 511.
filename = 'foo.txt' fileopen fp filename 0 :loop fileread fp 10 data messagebox data filename if result goto fclose goto loop :fclose fileclose fp
; Send 32 bytes from a binary file. filename = 'sample.bin' fileopen fhandle filename 0 if fhandle == -1 goto the_end call send_16_bytes ; send first 16 bytes fileseek fhandle 16 1 ; seek past next 16 without sending call send_16_bytes ; send next (last) 16 bytes fileclose fhandle goto the_end ;######################################### :send_16_bytes for i 1 16 fileread fhandle 1 str ; read one byte at a time so we can detect zero. if result == 1 break str2code integer str ; if zero then str will be empty and integer will be set to zero ;sprintf 'integer = 0x%02X' integer ;messagebox inputstr 'test' send integer next return ;######################################### :the_end