FileWriteBlock
Writes a string or buffer to a file. The data is written at the current file position. You may create the binary data by using the StrSetChar function or by reading the data from some other function. This function is similar to the FileWrite() function however you specify the length of data to write to the file. The FileWrite() function will send the data to the file until the sting terminator is found. FileWriteBlock() will ignore any string terminator and copy the length of bytes to the file. This allows this function to be used for binary data transfer.
Syntax
FileWriteBlock(File, Buffer, Length)
File:
The file number.
Buffer:
The data to write to the file. This may be a string or a string packed with binary data. The string terminator is ignored and the length argument specifies the number of characters to write.
Length:
The number of characters to write. The maximum number of characters you may write in one call is 255. (If you use a string without a terminator in a function that expects a string, or in a Cicode expression, you could get invalid results.) To use the string to build up a buffer, you do not need the terminating 0 (zero).
Return Value
The number of characters written to the file. If an error is detected -1 will be returned and IsError() will return the error code.
Related Functions
FileOpen, FileClose, FileWrite, FileReadBlock, StrSetChar
Example
STRING buf;
FOR I = 0 TO 20 DO
StrSetChar(buf, I, I); // put binary data into string
END
! Write binary data to the file.
FileWrite(File, buf, 20);
See Also