Equinox Online Help - Language Reference - A to Z

Home

PrintDevice

Applies to
SyntaxPrintDevice [DeviceExpression]
Action[Statement] Changes the destination of output generated by the Print statement.
ScopeUsable anywhere.
Notes

This statement redirects output generated by the Print statement to a specified device. The argument, DeviceExpression, can take the following values:

ValueRedirection
"Window"The default Print window
"None"No device, output is discarded
OtherDeviceExpression is used as a file name

If DeviceExpression is omitted, it defaults to Window. The selected device is maintained until Equinox is closed, or it is changed again.

If you are running in Windows, you can set the default device in the EQUINOX.INI file. Use the section name [Equinox] and set the value of the key name "PrintDevice" to the new default device name. eg To set a file as the default device you could use the following line in the EQUINOX.INI file:

PrintDevice = c:\temp\output.Log

DeviceExpression takes extra arguments which allow you to close the Print window from within a method. If the Print window is being used as the current device then executing PrintDevice with DeviceExpression omitted will close the window. The following example opens the Print window, prints "Hello" and then closes the window one second later:

Print "Hello"
Sleep 1
PrintDevice

Note that although the Print window is closed, its contents are retained. The next time that the window is opened, the string "Hello" will still be there.

DeviceExpression may also be supplied as a null string (ie ""). This also closes the Print window, but the contents of the window are cleared. This example has the same effect as the previous example, but the next time that the Print window is opened the string "Hello" will not be there.

Print "Hello"
Sleep 1
PrintDevice ""

The PrintDevice statement allows you to specify an external text file as the print device, in one of two ways:

ModeDescription
Binary modeEach line is followed by a carriage return only
Text modeEach line is followed by both a carriage return and line feed

By default, PrintDevice opens an output file in binary mode. The following example opens the file TEST.TXT in binary mode:

PrintDevice "test.txt"

To open a file in text mode, you must include the string "FILE:" at the start of the file name. eg To open TEST.TXT in text mode:

PrintDevice "file:test.txt"

When you use Print to write the first line to a file, the file is automatically opened. If the file does not exist, then it is created. However, the file is not automatically closed until Equinox is shut down.

If required, you may close the file manually using the PrintDevice statement. If you omit DeviceExpression, or supply it as a null string, then the current output file is closed. This does not prevent you from printing to the file, as a Print statement will automatically reopen it, but it does allow other applications to access the file.

Compare this use of DeviceExpression with its use when the Print window is selected as the output device. In both cases the device is closed, but note that whereas using a null string for DeviceExpression will empty the Print window, it will not empty an output file.

Note that if you are using a network version of Equinox, you must specify a local file. The Print statement cannot use a server file as an output device.

CategoryDebugging
See Also Assert, Print, ReportError, Stop
Example

The following example uses the PrintDevice statement to implement an error log. Errors are reported to the screen and printed in an external file called ERROR.LOG.

procedure LogError Number error, String msg, Number severity
ReportError error, msg, severity

PrintDevice "error.Log"
Print Today, Now, "Error:", msg

if SysError then
Print "current table", CurrentTableName, Print "SysError = "; SysError
end if

PrintDevice
end procedure | LogError