Command SET PRINTER Foundation

Sends screen output to the printer.

Syntax
SET PRINTER on | OFF | <lToggle>
SET PRINTER TO [<cDevice> | <cFileName> [ADDITIVE] ]
SET PRINTER TO OBJECT <oXbpPrinter>
BScope:!EF process wide
Parameters
<lToggle>
<lToggle> is a logical expression which must appear in parentheses. Instead of a logical expression, the option ON can be specified for the value .T. (true) or OFF for the value .F. (false). When .T. or ON is specified, all screen output except the output performed using @...SAY, is also sent to the printer.
<cDevice>
<cDevice> is the name of the output device or channel to which the print output is to be sent. It can be specified either as a literal or as a character expression in parentheses. It can be local or a device reached over a network. If <cDevice> does not exist, an ASCII file is created with this name.
<cFilename>
<cFilename> specifies the name of the ASCII file to which the print output is diverted. The name must contain the drive and path if they are necessary. It can be specified either as literal or as a character expression in parentheses. When the file name is specified without a file extension, the extension ".PRN" is used by default.
ADDITIVE
The option ADDITIVE appends the screen output to the file <cFileName>. If this option is not used, the contents of the file are first deleted if the file already exists. If the file with the name <cFileName> does not exist, it is created.
<oXbpPrinter>
If <oXbpPrinter> is used to specify an instance of the XbpPrinter class, printer output is sent to the corresponding Windows printer device. This syntax allows to use the SET PRINTER command to address printers independent of a specific port connection.
When the command SET PRINTER TO is called without argument, the current output channel or file is closed and the default output device PRN again is active.
Description

The command SET PRINTER ON sends all screen output occurring without specification of coordinates to the printer in addition to the screen. This includes output using ? or ?? as well as all commands supporting the option TO PRINTER. Screen output performed using the command @...SAY is unaffected. To send output performed using @...SAY to the printer, the output device is set beforehand to the printer using SET DEVICE TO PRINTER.

During printing, screen output can be turned off with SET CONSOLE OFF. This command has no effect on @...SAY commands.

Using the command SET PRINTER TO, the print output can be sent to a specific output channel or a specific output device. Valid device names are LPT1, LPT2, LPT3 (parallel ports), as well as COM1 and COM2 (serial ports) and finally CON and PRN. The default output device is PRN. For network printers, the format \\server\printername is also accepted as a valid device name. Furthermore, a file name can be specified to send the print output to a file. SET PRINTER TO without argument closes the file or the output channel and print output again occurs to PRN.

Print output is terminated using SET PRINTER OFF.

If syntax SET PRINTER TO OBJECT is used, the printer object is opened in line printer mode. Not all printers support this mode. So-called GDI printers and special-purpose drivers such as for PDF generation may produce no output when used via the SET PRINTER TO OBJECT command.

The printer may not be associated with a presentation space for as long as it is being used for output with SET PRINTER TO OBJECT.

Examples
SET PRINTER - output to the printer using ?

// In the example, addresses from an address file are 
// listed. The output occurs only at the printer and 
// not on the screen. 

PROCEDURE Main 
   USE Address NEW 

   SET PRINTER ON 
   SET CONSOLE OFF 

   DO WHILE .NOT. Eof() 
      ? LName, FName 
      ? Street 
      ? City + ",", State, Zip 
      ? 
      SKIP 
   ENDDO 

   SET PRINTER OFF 
   SET CONSOLE ON 

RETURN 
SET PRINTER - output with @...SAY to the printer
// This example is identical to the previous one, except 
// that output occurs using @...SAY. Also, SET DEVICE TO 
// PRINTER must be called. Print output occurs on LPT1. 

PROCEDURE Main 
   USE Address NEW 

   SET DEVICE TO PRINTER 
   SET PRINTER TO LPT1 

   DO WHILE .NOT. Eof() 
      @ 0, 0 SAY Trim(FName) +" "+ Trim(LName) 
      @ 1, 0 SAY Trim(Street) 
      @ 2, 0 SAY Trim(City) + ", " + Trim(State) + " " + Zip 
      @ 3, 0 SAY "" 
      SetPrc( 0 ,0 ) 

      SKIP 
   ENDDO 

   SET DEVICE TO SCREEN 
   SET PRINTER TO 
RETURN 
Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.