WRITEBYTES Function

Writes a certain number of bytes to a file.

Category: External File
Returned data type: Integer
Note: The returned value is an integer representing the number of bytes written.

Syntax

fileobject.WRITEBYTES(<number_of_bytes, buffer>)

Required Arguments

number_of_bytes

an integer specifying the number of bytes that is written to the file. This parameter can be specified as a number, field name, or expression.

buffer

a string that contains the bytes that need to be written. This parameter can be specified as a fixed string, field name, or expression.

Details

The WRITEBYTES method writes the specified number of bytes to a file starting at the current position in the file. This method overwrites data that exists at the current position in the file. If the current position in the file plus the number of bytes to be written is larger than the current file size, then the file size is increased.
If buffer is larger than number_of_bytes specified, then only the first number_of_bytes from buffer is written. The file needs to be opened in Write or Append mode for this method to work. The method returns the actual number of bytes written.
This method is normally used to write binary files. To write text files, the WRITELINE() method can be used.

Example

string input
file f
 
string = "this is longer than it needs to be"
f.open("C:\filename.txt", "rw")
// This will write to the beginning of the file
// Only the first 10 bytes from the string will be written
// If the file was smaller than 10 bytes it will be automatically
// appended
f.writebytes(10, input)
 
f.close()