Release 10.1A: OpenEdge Development:
Programming Interfaces

> ## Additional options for printing in Windows

> In Windows, you can also get a list of printers, change the default printer for the session, and provide access to the Print dialog box.

> ##### Getting a list of printers

> You can use the `GET-PRINTERS` option of the `SESSION` statement to obtain a list of the printers configured for the current system. The following example shows you how to obtain the list of currently configured printers, select a printer, and print to it:

> i-wgetls.p
>     /*1*/ DEFINE VARIABLE printer-list AS CHARACTER.
>           DEFINE VARIABLE printer-idx AS INTEGER.
>     /*2*/ printer-list = SESSION:GET-PRINTERS().
>     /*3*/ printer-idx = LOOKUP("SpecialPrinter", printer-list).
>     /*4*/ IF printer-idx > 0 THEN DO:
>             MESSAGE "output" VIEW-AS ALERT-BOX.
>               OUTPUT TO PRINTER "SpecialPrinter".
>           END.
>     /*5*/ ELSE DO:
>             OUTPUT TO PRINTER.
>           END.
>           FOR EACH customer FIELDS (country name) WHERE country = "Finland" :
>             DISPLAY NAME country.
>           END.
>     /*6*/ OUTPUT CLOSE.

> The following list explains the important elements in the example above:

> 1. Create two variables: one for the output of `SESSION:GET–PRINTERS`; the other, for the output of `LOOKUP`.

> 2. The `SESSION: GET–PRINTERS` method returns a comma-separated list of printers that are currently configured on the system.

> 3. The `LOOKUP` function obtains an integer that gives the position of “SpecialPrinter” in the list. If the printer is not in the list, it returns a 0.

> 4. The `IF` statement determines whether the printer “SpecialPrinter” is available and if so, prints to it.

> 5. If the printer “SpecialPrinter” is not available, the `ELSE` `DO` statement prints to the default printer.

> 6. The `OUTPUT` `CLOSE` statement stops sending output to the current destination and redirects output to the destination used prior to `OUTPUT` `TO`. See the "Stream I/O vs. screen I/O" section for more information.

> ##### Changing the default printer

> To change the default printer for the session, you can use the `PRINTER–NAME` option of the `SESSION` statement as shown in the following example:

> i-wchpr.p
>     /*1*/ DEFINE VARIABLE printername AS CHARACTER.
>     /*2*/ printername = SESSION:PRINTER-NAME
>     /*3*/ SESSION:PRINTER-NAME = "\\AB1\hplaser".
>     /*4*/ OUTPUT TO PRINTER.
>           FOR EACH customer:
>             DISPLAY name SPACE balance.
>           END.
>     /*5*/ SESSION:PRINTER-NAME = printername.

> | To change the default printer:

> 1. Create a variable for the output of `SESSION:PRINTER–NAME`.

> 2. The `SESSION:PRINTER–NAME` attribute returns the name of the default printer.

> 3. The `SESSION:PRINTER–NAME` attribute sets another printer, `\\AB1\hplaser`, as the default printer.

> 4. The `OUTPUT TO PRINTER` prints the report on the printer \`\AB1\hplaser`.

> 5. The `SESSION:PRINTER–NAME` attribute restores the original default printer.

> ##### Providing access to the print dialog box

> You can use the `SYSTEM–DIALOG PRINTER–SETUP` statement to provide access to the Windows print dialog box. This allows the application user to set up the printer or even change the printer that receives the output.

Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095