See Also: File I/O Commands, Append_Output, Direct_Output, Read, Set_Channel_Position, WriteLn, Write_Hex, Channel command component, Sequential File I/O
To Write the values of one or more variables to a sequential file, device or text field.
Write [channel channelNum] value [ ... value]
Channel ChannelNum
Output Channel to Write data to. If omitted, the channel will be that specified in the last executed Append_Output, Direct_Output, Output, Write, or WriteLn command in which channel was specified or implied.
Value
Optional. May be of any simple data type or UChar[]. Additional values may be on the command line, separated by spaces, without limit.
Write Writes data to the output file or device named in the last previous Direct_Output command. The first Write command in the program Writes data from the variable(s) named in its argument(s) to the first line of the output file or device until an end of line character is output (usually with a WriteLn). Subsequent Writes Write to the same file or device wherever the last Write left off.
Direct_Output "output.txt"
Write "Alice In Wonderland"
In this example, the literal string Alice In Wonderland (without quotation marks) is output to file output.txt.
The point in a file at which writing after an Append_Output command is done can also be changed by use of the Set_Channel_Position command. Write-ing before the end of a file overwrites existing data. There is no insert mode for sequential output.
Write does not add any delimiters, embedders, or other formatting characters to the output, not even spaces between values. You must provide any such characters in arguments to the Write command. Suppose, for example, that you wished to output two fields from Database File car, and that the field contents needed to be embedded in quotation marks (") and each field separated from the other by a comma. This command would do so:
Write '"' Car.Make '","' Car.Model '"'
Here, single quotation marks (') are used to make literal constants out of the combinations of embedding and delimiting characters required in the output. If the value of Car.Make were CADILLAC, and of Car.Model, EL DORADO, the output would be:
"CADILLAC","EL DORADO"
In long and numerous commands, and with data which itself contains characters used as embedders, you can Write, and read, your commands more easily if you place the required characters into DataFlex variables, and use the variables to insert the required characters into the output.
String sTerm sInter
Move '"' to sTerm
Move '","' to sInter
Write sTerm Car.make sInter Car.Model sTerm
This example would output exactly the same string as the example above.
It is unnecessary ever to use the channel feature unless at some point you need more than one output destination, or more than one input source, at the same time in your program.
When value is an expression that contains multiple data types concatenated using String concatenation, non-String data types must be cast as String.
For example:
Integer iCount
Move 5 to iCount
Write ("The file contains "+ iCount + " lines")
WriteLn
will result in 0 being written out.
Integer iCount
Move 5 to iCount
Write ("The file contains "+ (String(iCount)) + " lines")
WriteLn
will result in "The file contains 5 lines" being written out.
The Write command can be passed a UChar array and it will write the entire array to out to the sequential output device. This can be used in place of a string variable and has the advantage that you don't have to worry about maximum string size and you don't have to concern yourself with embedded zeros.
If the variable passing the data is a UChar array, it will write each byte of the array to the output stream.
This can be used along with Set_Field_Value and Get_Field_Value, which have also been extended to support UChar arrays.
Procedure WriteToPDFFile String sOutFile
UChar[] PDFManual
// read a big field from your data file
Get_Field_Value Product.File_Number (RefTable(Product.PdfManual)) to PDFManual
// if there is a PDF write it to a file
If (SizeOfArray(PDFManual)) Begin
Direct_Output Channel 5 sOutFile
Write Channel 5 PDFManual
Close_Output Channel 5
End
End_Procedure
You must supply in the arguments to Write all delimiters, embedders, and other formatting characters required by whatever program is to use the output. Refer to the documentation for the target program for its requirements, and how to adapt the requirements of your particular data to those requirements. Common data formats which you can emulate with Write are ASCII, sequential, comma-delimited, mail merge, and line-delimited.
If you want to output a new line after sending data for the last argument on the command line, use the WriteLn command.
Do not confuse Write with the print command. Write sends data to a non-DataFlex file or device. Print moves data to a window.
The output file or device must be opened with the Direct_Output or Append_Output command prior to using Write.