Welcome!

PowerBuilder Authors: Dan Joe Barry, Carmen Gonzalez, Ian Thain, Yakov Werde, Paul Slater

Related Topics: PowerBuilder

PowerBuilder: Article

The Power To Print...

Makes your life a lot easier

The latest PowerBuilder productivity enhancements will make our jobs as developers easier and reduce development time. Among the many improvements in PowerBuilder 8 are the additions to PowerScript of four printer functions that support changing the default printer and its document properties. These functions, printGetPrinter, printGetPrinters, printSetPrinter, and printSetupPrinter, implement library routines that, in previous versions of PowerBuilder, would have required external function calls or the use of third-party products.

Let's begin this discussion with the two getter functions, printGetPrinter and printGetPrinters. Both return tab-delimited strings containing the printer, driver, and port names, allowing each to be easily loaded into a DataWindow using the importString method (see Listing 1). The difference between these functions is that printGetPrinter returns only the default printer (or the printer that's set as current with printSetPrinter), while printGetPrinters returns a list of all printers available to the system. It should be noted that printGetPrinter won't return the default printer if that printer was changed to default outside of the application.

Complementing the getter functions is the setter function printSetPrinter. This function sets the printer you'll be using for the next print task. printSetPrinter is called with a single string parameter, printer_name (see Listing 2), and won't affect currently open print jobs. The printer_name argument must be a valid printer name as returned by the printGetPrinters function.

The last function to discuss, printSetupPrinter, simply displays the printer's document properties dialog box provided by the system print driver, allowing users to specify document settings for the current printer (see Figure 1). The current printer can't be changed with this function (as is possible with the printSetup function).

To demonstrate these new functions I've included a small sample application consisting of one window and two DataWindows (one dropdown DataWindow). The application displays a list of available printers with associated driver and port names (printGetPrinters) defaulting to the current printer (printGetPrinter). Once the user chooses another printer from the dropdown DataWindow, that printer is made current (printSetPrinter). At any time the user may click the "Properties" button to display the printer's document properties dialog box (see Figure 1) for the currently selected printer (printSetupPrinter).

Sybase's work with the PowerBuilder development community has produced many new enhancements in PowerBuilder 8 that can make any developer's life easier. When you have the chance, peruse the "What's New" section of the help file. I'm sure you'll find many improvements, including the functions discussed here, that you can immediately use in your code.

More Stories By Todd Jones

Todd Jones is a senior consultant with Sybase Professional Services in Denver, Colorado. He has over 11 years of experience in the IT industry and is certified as a PowerBuilder Developer Associate and a Sybase Server Administrator Associate.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.