Print Control Variables

Device Selection Variables

output_device can be set to select the output destination bitmask. filename allows you to name the files created by a program. These two variables must be set before initialising printing.

filename

filename contains the name of the file created if you choose file output. The default filename extension .PRN will be added if you specify a filename without an extension. This variable behaves in rather a strange way:

output_device

output_device determines whether to produce screen, printer or file output.

The initial value of output_device depends on the responses to the questions in the Default Output devices dialog. You can modify the value of output_device to change the devices that will be opened by subsequent Device Select procedures.

output_device must be assigned before initialising printing. Setting output_device afterwards has no effect. For this reason, if you wish to use output_device, initialise printing in a procedure body. If printing is intialised by the program header, you cannot change output_device beforehand.

The value of output_device is the sum of various flags as shown in the table below. For each value the name given to the value in the DP4 C API is also shown. If you use output_device values extensively in your QAB programs it is suggested you create QAB macros using these names to make your code easier to understand.

These are the only flags you should use. Other flags are either meaningless in QAB or will cause errors.

Value DP4UIAPI.h name Effect Description
1 SCREEN Screen output Print output is scrolled on to free lines of the screen
2 PRINTER Printer output Print output is sent to the printer port specified by the device type
4 DP4_FILE File output Print output is written to a file. The file name is contained in the variable filename
32 OFFER_DELETE Offer Delete If output is sent to a file and the file already exists allow the user to choose whether to append or delete.
256 NOCTL No control characters  Omits the printer control characters, for file output
512 NO_APPEND Restart file If the filename exists, the file will be deleted
8192 NO_SELECT No run time selection  Prevents the print options dialog being offered at run time unless there is a problem selecting the requested output devices
16384 NONE_ALLOWED Permit none Permit no output (screen,printer,file all off)
32768  NO_RETRY Prevent retry  Prevent the print options dialog being offered even when there is a problem selecting the requested output devices

Some of these flags have additional/different effets on the output when you are using a DFPRINT based output device. Please refer to the documentation of the dvc_choose() function for further information.

Example:

To include output_device in field processing define it with data type I. You can use any length.

A print program is required which depending on a certain condition prints either to a file or to a printer.

The program sets the value of OUTPUT_DEVICE in formula processing in a procedure body before the one that initialises the printer The formula below shows how the value of OUTPUT_DEVICE can be set:

IF condition then 
  2 {select the printer}
ELSE
 (4+512){select file output to new file}

You might also examine the value of output_device after printing has started. For example if printing was only goin to screen you might decide to print a narrow version of a report, missing out coluns that take up too much space.

Variables Used During Printing

There are several QAB standard variables related to printing which you may find useful. line_nr and page_depth, page_width control where a new page should be started. page_nr can be used to print page numbers.

line_nr

line_nr contains the number of the last line written to the current page. Within a print procedure, line_nr includes the form output in that procedure. If used in an entry condition formula for a print procedure line_nr represents the last line printed.

When a printer is first selected or when a new page is started, line_nr is set to 0.

For printing to DFPRINT an approximate line_nr is calculated based on the position on the page divided by the height of the default font.



Example:

To include line_nr in field processing define it with data type I. You can use any length.

A report has a header on each page followed by repeated lines. When linenr is within 6 lines of the page depth (see below) a new page should be started

The procedure for printing a new header includes the entry condition:

line_nr+6 >= page_depth

page_nr

page_nr contains the current page number. It is incremented before field processing if the form output method is Top of form. It is incremented after field processing if the form options specify a new page at end.

To include page_nr in field processing define it with data type I. You can use any length.

page_depth

The value of page_depth is taken from the selected printer settings (the device type). It is set when the printer is selected.

For printing to DFPRINT an approximate page_depth is calculated based on the actual paper size and margins selected by the Windows print dialog, or in the DP4 configuration file



Example:

To include page_depth in field processing define it with data type I. You can use any length.

See example for line_nr above.