BINWR ( Write As , Bytes To Write , Text / Value )
The BINWR procedure writes data to a binary file. The data (Text / Value) is written according to the data type indicated in the Write As parameter and in the case of a string (text) the program will write as many bytes from the text as indicated in the Bytes To Write parameter.
Parameter |
Description |
Accepted Values / Data Type |
Write As |
Designates the data format to write. Will generate an error if the Text / Value is not found to be compatible with this data format. |
INTEGER : Writes Text / Value as a 4 byte integer SINGLE: Writes Text / Value as a 4 byte single precision decimal (7-8 significant figures) DOUBLE: Writes Text / Value as a 8 byte double precision decimal (15-16 significant figures) EXTENDED: Writes Text / Value as a 10 byte extended precision decimal (19-20 significant figures) BOOLEAN: Writes Text / Value as a 4 byte boolean (ie., True / False) STRING: Writes Text / Value as a string variable, writes Bytes To Write bytes to the text file |
Bytes To Write |
Only used if Write As = STRING. Designates the number of bytes in string to write. If Bytes To Write > size of string then remainder of bytes written are space character. If Bytes To Write < size of string then the string is trimmed to size of Bytes To Write and written to file. |
Integer |
SizeOfString (Result Variable , String / String Variable )
The SizeOfString procedure determines the number of bytes required to completely write a String / String Variable to a binary file and stores the result in a user variable (Result Variable).
EXAMPLE
StartPrintToFile(&Binary_File,BINARY,WINDOWS,OVERWRITE)
SizeOfString(&String_Size, %Project.Title)
BINWR(INTEGER, {not required since NOT STRING}, &String_Size)
BINWR(STRING, &String_Size, %Project.Title)
EndPrintToFile(&Binary_File)
This example opens a binary file for write access and writes the length of the string type project variable %Project.Title as an integer followed by the entire string. This example is relevant because it is often necessary when writing strings to binary files to write the length of the string to file as an integer prior to writing the string. This may be done to ensure when the intended application reads the file, it can first read the string length in order to know the number of bytes it should read into the string variable.