Sams Teach Yourself Visual Basic 6 in 24 Hours
- Table of Contents
- Copyright
- About the Author
- Acknowledgments
- Introduction
- Who Should Read This Book
- What This Book Will Do for You
- Can This Book Really Teach Visual Basic in 24 Hours?
- What You Need
- Files on the Visual Basic Distribution CD-ROM
- Conventions Used in This Book
- Enough! Time Is Ticking!
- Part I: Introducing Visual Basic
- Hour 1. Visual Basic at Work
- Hour 2.Analyzing Visual Basic Programs
- Hour 3.Controls and Properties
- Hour 4.Examining Labels, Buttons, and Text Boxes
- Part II: Coding the Details
- Hour 5.Putting Code into Visual Basic
- Hour 6.Message and Input Boxes
- Hour 7.Making Decisions
- Hour 8.Visual Basic Looping
- Part III:Putting Code to Work
- Hour 9.Combining Code and Controls
- Hour 10.List Boxes and Data Lists
- Hour 11.Additional Controls
- Hour 12.Dialog Box Basics
- Part IV:Programming with Data
- Hour 13.Modular Programming
- Hour 14.Built-In Functions Save Time
- Hour 15.Visual Basic Database Basics
- Hour 16.Printing with Visual Basic
- Introducing Printing
- Preparing the User for Printing
- Introducing the Printer Object
- The Print Method
- Starting to Print
- Summary
- Q&A
- Workshop
- Part V:Sprucing Up Programs
- Hour 17.Menus and Visual Basic
- Hour 18.The Graphic Image Controls
- Hour 19.Toolbars and More Graphics
- Hour 20.Writing Correct Applications
- Part VI:Advancing Visual Basic Applications
- Hour 21.Visual Basic and ActiveX
- Hour 22.Object Basics
- Hour 23.Distributing Your Applications
- Hour 24.Online Visual Basic
- Part VII:Appendixes
- Appendix A.Operator Precedence
- Appendix B.Answers
- Appendix C.Using the CD-ROM
Introducing the Printer Object
Visual Basic applications send all printed output to a special Visual Basic object called the Printer object. The Printer object supports several property values and methods with which you determine the look of the printed output.
The Printer keyword specifies the Printer object to which your applications will direct all output. There is no Printer control on the Toolbox window. All access to the Printer object must take place using Visual Basic code.
The commands that your application sends to the Printer object are generic Windows printer commands. The Windows print spooler converts those generic commands to a specific printer's commands. Therefore, you only worry about what you want printed and let the Windows print spooler worry about how the output is produced.
Throughout this book, when you have learned about a new object such as the Command Button control, you have learned about the properties that relate to that object. Before using the Printer object, you should see the properties available for it so that you'll know what you can do with printed output from within Visual Basic. All the Printer object's properties are listed in Table 16.1.
Table 16.1. The Printer object's properties.
| Property | Description |
| ColorMode | If 1 (or if set to the vbPRCMMonochrome named literal), output prints in monochrome (shades of white and black) even if you use a color printer. If 2 (or if set to the vbPRCMColor named literal), output prints in color. |
| Copies | Specifies the number of copies to print. |
| CurrentX | Holds the horizontal print column from the upper-left corner of the page, measured either in twips or the scale defined by the ScaleMode properties. |
| CurrentY | Holds the vertical print row from the upper-left corner of the page, measured either in twips or the scale defined by ScaleMode properties. |
| DeviceName | The name of the output device, such as a printer driver, to which you want to print. |
| DrawMode | Determines the appearance of graphics that you draw on the printer. |
| DrawStyle | Specifies the style of any graphical lines that your application draws. |
| DrawWidth | Specifies the width of lines drawn, from 1 (the default) to 32,767 pixels. |
| DriverName | The name of the printer driver (don't specify the driver's extension). |
| Duplex | If 1 (or if set to the named literal vbPRDPSimplex), printing will occur on one side of the page. If 2 (or if set to the named literal vbPRDPHorizontal), printing will occur on both sides (if your printer supports double-sided printing) using a horizontal page turn. If 3 (or if set to the named literal vbPRDPVertical), printing will occur on both sides (if your printer supports double-sided printing) using a vertical page turn. |
| FillColor | Specifies the color of printed shapes. Determines the shading density for noncolor printed output. |
| FillStyle | Contains the style pattern of printed shapes. |
| Font | Returns a font that you can use for setting font attributes. |
| FontBold | Contains either True or False to determine whether subsequent printed output will be boldfaced. |
| FontCount | Specifies the current printer's number of installed fonts. |
| FontItalic | Holds either True or False to determine whether subsequent output will be italicized. |
| FontName | Holds the name of the current font being used for output. |
| Fonts | Contains a table of values that act as if they were stored in a control array. Fonts(0) to Fonts(FontCount-1) holds the names of all installed fonts on the target computer. |
| FontSize | Holds the size, in points, of the current font. |
| FontStrikeThru | Holds either True or False to determine whether subsequent output will be printed with a strikethrough line. |
| FontTransparent | Holds either True or False to determine whether subsequent output will be transparent. |
| FontUnderline | Holds either True or False to determine whether subsequent output will be underlined. |
| ForeColor | Specifies the foreground color of printed text and graphics. (The paper determines the background color.) |
| hDC | A Windows device context handle for advanced Windows procedure calls. |
| Height | Holds the height, in twips, of the current printed page. |
| Orientation | If 1 (or if set to the named literal vbPRORPortrait), output prints in portrait mode (printing occurs down the page). If 2 (or if set to the named literal vbPRORLandscape), output prints in landscape mode (printing occurs across the page). |
| Page | Contains the page number currently being printed and updated automatically by Visual Basic. |
| PaperBin | Specifies which paper bin the print job will use. You can search the online help for the PaperBin property for several named literals you can use to specify different kinds of bins. |
| PaperSize | Specifies the size of paper the print job will use. You can search the online help for the PaperSize property for several named literals you can use to specify different sizes of paper. |
| Port | Specifies the printer port, such as LPT1:. |
| PrintQuality | Determines how fine the print quality will appear. If -1 (or set to the vbPRPQDraft named literal), the printing quality is the least, but the print completes quickly. If -2 (or set to the vbPRPQLow named literal), printing occurs in a low-resolution mode. If -3 (or set to the vbPRPQMedium named literal), printing occurs in a medium resolution mode. If -4 (or set to the vbPRPQHigh named literal), printing is the slowest but the highest quality. |
| ScaleHeight | Specifies how many ScaleMode units high each graphic will be upon output. |
| ScaleLeft | Specifies how many ScaleMode units from the left of the page subsequent printed output appears. |
| ScaleMode | Sets the unit of measurement for all subsequent printed output that appears. |
| ScaleTop | Specifies how many ScaleMode units from the top of the page all subsequent printed output appears. |
| ScaleWidth | Specifies how many ScaleMode units wide each graphic will be upon printed output. |
| TrackDefault | If True, the specified printer changes if you change the default printer at the operating system level. If False, the specified printer remains the same during the program's operation even if the system's default printer changes during the program's execution. |
| TwipsPerPixelX | Specifies the number of screen twips that each printer's dot (or pixel) height consumes. |
| TwipsPerPixelY | Specifies the number of screen twips that each printer's dot, or pixel, width consumes. |
| Width | Holds the size of the page width (measured in twips). |
| Zoom | Specifies the percentage at which printed output prints. A negative value scales the output down (smaller), 0 requests no scaling, and a positive value scales the output up (larger). |
Table 16.1 contains many printer properties; fortunately, you'll use only a few of the properties for most of your printing needs. The font-related printer properties take care of just about all your printing jobs that are textual in nature.
Unlike most of Visual Basic's control objects, the Printer object's methods are much more important than its property values. Table 16.2 contains a complete list of the methods supported by Visual Basic's Printer object.
Table 16.2. The Printer object's methods.
| Method | Description |
| Circle | Draws a circle, an ellipse, or an arc on the printer. |
| EndDoc | Releases the current document, in full, to the print spooler for output. |
| KillDoc | Immediately terminates the output and deletes the current print job from the print spooler. |
| Line | Draws lines and boxes on the page. |
| NewPage | Sends a page break to the printed output so that subsequent output appears on the next page. |
| PaintPicture | Draws a graphic image file on the printer. |
| Prints numeric and text data on the printer. | |
| PSet | Draws a graphical point on the printed output. |
| Scale | Determines the scale used for measuring output. |
| ScaleX | Converts the printer's width to ScaleMode's measurement unit. |
| ScaleY | Converts the printer's height to ScaleMode's measurement unit. |
| TextHeight | Determines the full height of text given in the scale set with Scale. |
| TextWidth | Determines the full width of text given in the scale set with Scale. |
By far the most widely used Printer object methods are the Print, EndDoc, and NewPage methods. After you master these three methods, you'll rarely need to use any other methods.
The Print Method | Next Section

Account Sign In
View your cart