Logo

Hacker’s Guide to Visual FoxPro
An irreverent look at how Visual FoxPro really works. Tells you the inside scoop on every command, function, property, event and method of Visual FoxPro.

GETPRINTER(), PRTINFO(), Sys(1037)

These three functions are a wonderful relief from the printing challenges of early FoxPro versions. GETPRINTER() presents the Windows dialog to choose the printer for output, PRTINFO() allows the programmer to query all the details of the capabilities of the printer, and SYS(1037) puts up a decent Print Setup dialog.

Usage

cPrinterChosen = GETPRINTER( )

Parameter

Value

Meaning

cPrinterChosen

Character

The name of the printer chosen.

Empty String

User chose Cancel, or closed the dialog box any way other than selecting OK.

This is a weak-looking dialog, allowing the user only to select a printer, but not set other properties. We don’t understand why we don’t get the full dialog we see in REPORT FORM…TO PRINT PROMPT.

Example

cPrinter = GETPRINTER()
IF NOT EMPTY(cPrinter)
  SET PRINTER TO NAME (cPrinter)
ENDIF

Usage

nResult = PRTINFO( nIndex [, cPrinterName ] )

Parameter

Value

Meaning

nIndex

1

Orientation.

2

Paper size. If –1 is returned, use parameters 3 and 4 to determine the custom paper size.

3

Paper length, in tenths of a millimeter.

4

Paper width, in tenths of a millimeter.

5

Scaling factor.

6

Number of copies to print.

7

Paper tray chosen as the default paper source.

8

Print quality, expressed in dots per inch, if a positive number, or a relative scale (Draft, Low, Medium, High) if a negative number (–1 to –4, respectively).

9

Color printing? 1=Color, 2=Single color.

10

Printer duplexing (printing both sides of the page) mode.

11

Vertical resolution, in dots per inch.

12

Options for printing TrueType fonts.

13

Whether or not output is collated.

cPrinterName

Character

The name of the printer, as returned by GETPRINTER() and APRINTERS().

nResult

–1

With two exceptions noted above (paper size, number 2 and print quality, number 8), a negative return indicates the information is unavailable. Either this feature may not be implemented for this printer, or you may have specified a printer that doesn't exist.

Integer

Result of querying the particular parameter above, as documented above and in the help file.

These return values can be used to very precisely plan out how output will appear on the page. This is tremendously useful if you are trying to generate reports on the fly, or trying to make a certain amount of material fit on a single page. Rather than trying to memorize the above 13 possible index values and what they’re good for, use the FoxPro.H file and the easier-to-use constant names included there.

Example

* Note that the following must be compiled
* to include FoxPro.H and run properly.
#INCLUDE \VFP\FOXPRO.H
? "Orientation: "
nResult = PRTINFO(PRT_ORIENTATION)
DO CASE
  CASE nResult = -1
    ?? "Not Available"
  CASE nResult = 0
    ?? "Portrait"
  CASE nResult = 1
    ?? "Landscape"
ENDCASE

Usage

cEmptyString = SYS( 1037 )

The documentation erroneously claims that SYS(1037) brings forth a Page Setup dialog, and it even links to a description of the Page Setup dialog. However, calling this function brings up a dialog labeled "Print Setup," which is obviously not the Page Setup dialog.

In the Print Setup dialog, the Properties button does allow you to adjust the default paper size, orientation and other settings specific to your printer. And it works just fine, unless you've tinkered with the Page Setup option from the menu while creating or editing your report. If you want to give the user the ability to use his SYS(1037) settings instead, you need to delete the stored settings from the report. They're in TAG and TAG2 of the first record of the FRX—you can use something like this:

SYS(1037)
SELECT * FROM MyReport.FRX INTO CURSOR TempReport
SELECT TempReport
BLANK FIELDS TAG, TAG2
REPORT FORM TempReport TO PRINT

There are few areas of the product that cause more confusion and grief than printing. Much of this is due to a lack of understanding of what the product can do, some to misleading documentation, and some to the fact that “everyone knows” Fox can’t do something. Carefully examine the functionality and return values of each of these functions, and we think you’ll find that Fox can do whatever printing task is needed.

To see a Page Setup dialog, call up a report in the Report Designer, and select—surprise!—Page Setup from the File menu. There are options for the number of columns, whether the print area occupies the whole page (or just the printable portions), the order in which labels should print (left to right, or up and down) and the margin to use. These would be some nice features to be able to call up while a user is trying to fit text on his labels, without having to call up the entire designer.

The help for FoxPro 2.6a claims that SYS(1037) only works for the Macintosh. Wrong. It also brings up the Print Setup dialog in version 2.6a for Windows. Where it does, finally, bring up the Page Setup dialog is on the Mac only. Page Setup on the Mac doesn’t have the Page Layout options of the Report Writer, either, but the name of the dialog is, in fact, Page Setup. We suspect this is just a case of bad translation among the several platforms, but we sympathize with our poor fellow developers who spend time trying to get the right dialog box to come up.

Example

=SYS(1037)

See Also

#INCLUDE, APrinters(), Set Printer