Try OpenEdge Now
skip to main content
Programming Interfaces
Input/Output Processes : Alternate I/O Sources : Changing the output destination : Additional options for printing in Windows : Getting a list of printers
 
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 i-wgetls.p procedure 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 NO-UNDO.
      DEFINE VARIABLE printer-idx  AS INTEGER   NO-UNDO.

/*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
        OUTPUT TO PRINTER.

      FOR EACH Customer NO-LOCK
        WHERE Customer.Country = "Finland" :
        DISPLAY Customer.Name Customer.Country.
      END.

/*6*/ OUTPUT CLOSE.
The following list explains the important elements in i-wgetls.p:
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 StreamI/O vs. screen I/O for more information.