Skip to content

Writing Data

There are three DataFlex commands for writing data to a sequential I/O file: Write, Writeln, and Write_Hex. The first two are detailed below. Refer to the Language Reference for more information about each of these commands.

Write

The Write command writes data to the output file. It appends the data to the output file without creating a new line. A Writeln statement must be executed to advance output to the next line. The syntax for the Write command is:

Write [channel {channel-num.}] {value1} [{value2 .. valueN}]

Where:

  • {channel-num.} is the channel assigned to the file that is being read.
  • {value1 .. N} are the data items that are written. {value} can be any constant, variable, or expression.

If the channel specification is omitted, then data is written to whichever channel was last referenced, or channel 1 if no channel has been referenced. Each Write command must specify at least one {value} to be written.

An example of using the Write command is:

Direct_Output "c:\Names.txt"
Write "Bill, Bob, Jane"
Writeln
Write "Mary, Stuart, John"
Writeln
Close_Output

Writeln

The Writeln command writes data to an output file and then outputs an end-of-line character. The syntax of the Writeln command is:

Writeln [channel {channel-num.}] [{value1 .. valueN}]

Where:

  • {channel-num.} is the channel assigned to the file that is being read.
  • {value1 .. N} are the data items that are written. {value} can be any constant, variable, or expression.

If the channel specification is omitted, then data is written to whichever channel was last referenced, or channel 1 if no channel has been referenced. If no {value} is specified, then the Writeln command will simply add an end-of-line character to the output file.

An example of using the Writeln command is:

Direct_Output "c:\Names.txt"
Writeln "Bill, Bob, Jane"
Writeln "Mary, Stuart, John"
Close_Output