Equinox Online Help - Language Reference - A to Z

Home

FileWriteBinary

Applies to
SyntaxFileWriteBinary HandleItem, Item, LengthExpression
Action[Statement] Writes a specified number of bytes from a string to a random file.
ScopeUsable anywhere
Notes

This statement was formerly known as FileWriteString.

Any existing calls to FileWriteString will automatically be updated to FileWriteBinary, unless they are contained in a Macro, in which case you will need to manually update these calls.

This statement writes data of specified length from strings within the method language to a random file. Whereas the FileWrite statement writes formatted binary data, this statement writes unformatted data up to the length specified in LengthExpression.

If LengthExpression is less than the size of the item, Equinox writes the specified amount only. Note that this may lead to unexpected and environment-specific results if the item is not a string.

This statement will not work if the file has been opened as a sequential file.

The HandleItem parameter must be of Equinox variable type Handle and is the handle of the file which was opened with the FileOpen statement.

The system workarea SysError is set to a non-zero value if an error occurs, otherwise zero.

CategoryFile IO
See Also FileClose, FileCloseAll, FileDelimiters, FileInput, FileInputLine, FileLock, FileMovePosition, FileOpen, FilePosition, FilePrint, FileRead, FileReadLine, FileReadBinary, FileReadFile, FileUnlock, FileWrite, FileWriteBinary, FileWriteFile
Example

This example creates a log in a random file of certain database operations. It uses the function Len to determine the length of the string to output.

string Routine
handle hnd

FileOpen "OPLOG.DAT", RandomReadWrite, hnd

if hnd = -1 then
Alert "File Opening Error"
exit method
end if

| Go to end of file
FileMovePosition hnd, -1
Routine = "Database Archived at " & StrTime(Now, "%12h:%0m %am") & " on " & StrDate(Today, "%day %nth %month %year.")
FileWriteBinary hnd, Routine, Len(Routine)

| Example text which could be placed in the file is
| Database Archived at 2:32 pm on Monday 6th November 1995.
FileClose hnd