Lesson XIX:           The Printer Object

 

Objectives

ü      To be able to print texts and graphics using the Print object

ü      To be able to manipulate the printer object to print according to user preferences

 

 

 

 

Visual Basic applications send all printed output to a special VB object called the Printer object.  The Printer Object supports several property and methods that help you customize how the print out will look like on paper.

 

The following table lists the Printer’s properties.

 

Property

Description

ColorMode

1: vbPRCMonochrome, outputs prints in monochrome

2: vbPRCMColor, outputs prints in color

Copies

Specifies the number of copies to print.

CurrentX

Holds the vertical print row, from the upper-left corner of the page, measured either in twips or the scale defined by the ScaleMode property.

DrawWidth

Specifies the width of lines drawn, from 1 (default) to 32767 pixels.

FillColor

Specifies the color of printed shapes.

FillStyle

Contains the pattern of printed shapes.

FontBold

Boolean.  Determines whether subsequent printed output will be boldfaced or not.

FontItalic

Boolean: Determines whether subsequent printed output will be italicized or not.

FontName

Holds the name of the current font being used for output.

FontSize

Holds the size, in points, of the current font.

FontStrikeThru

Boolean. Determines whether subsequent output will be printed with a strikethrough line.

FontUndeline

Boolean.  Determines whether subsequent output will be underlined.

ForeColor

Specifies the foreground color of printed text and graphics.

Height

Holds the height, in twips, of the current printed page.

Orientation

1: vbPRORPortrait, outputs prints in portrait mode.

2: vbPRORLandscape, outputs prints in landscape mode

Page

Contains the page number currently being printed and updated automatically by Visual Basic.

PaperBin

Specifies which paper bin the print job will use. Commonly-used values are:

1: vbPRBNUpper, Use paper from the upper bin.

2: vbPRBNLower, Use paper from the lower bin.

4: vbPRBNManual, Wait for manual insertion of each sheet of paper.

5: vbPRBNEnvelope, Use envelopes from the envelope feeder.

6: vbPRBNEnvManual, Use envelopes from the envelope feeder, but wait for manual insertion.

8: vbPRBNTractor, Use paper fed from the tractor feeder.

 

 

PaperSize

 

 

Specifies the size of paper the print job will use.  Commonly-used values:

1: vbPRPSLetter, Letter, 8 1/2 x 11 in.

5: vbPRPSLegal, Legal, 8 1/2 x 14 in.

9: vbPRPSA4, A4, 210 x 297 mm

256: vbPRPSUser, User-defined

PrintQuality

Determines how fine the print quality will appear.

1: vbPRPQDraft, least quality, but prints quickly

2: vbPRPQLow, low-resolution mode

3: vbPRPQMedium, medium-resolution mode

4: vbPRPQHigh, slowest quality

ScaleMode

Sets the unit of measurement for all subsequent printed output that appears.

1: vbTwips, Measured in twips (default)

2: vbPixels, Measured in pixels

5: vbInches, Measured in inches

6, vbMillimeters, Measured in millimeters

7: vbCentimeters, Measured in centimeters

Width

Holds the size of the page width (in twips).

The following are the methods of the Print object.

Method

Description

Circle

Draws a circle or an arc.

EndDoc

Releases the current document 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.

Print

Prints numeric and text data.

 

 

IN FOCUS: THE PRINT METHOD

 

The Print method handles almost all the printing jobs.  With this method, you can print literals, variables, constants, and expressions.  The syntax of the Print method is as follows:

 

Printer.Print <expression>

 

Below are examples on how to use the Print method:

Printing Literals

Examples:

Printer.Print 1

Printer.Print 12.5

Printer.Print “Computer Science”

Printer.Print                   ‘Prints a blank line

Note: Print method prints a new line after printing the expressions.

Printing Variables

Examples:

Fname = “Jennifer”

Age = 24

Printer.Print Fname

Printer.Print Age


Printing Expressions

Examples:

Printer.Print 45 + ( 4 * 3)

Printer.Print RawScore/TotalScore * 100

Printer.Print “Name: “ & Fname & Lname

 

Printing Multiple Values

Printer.Print “Score: “; intScore; “Letter Grade”; strLGrade

The Semi-colon keeps the printer’s print head at the end of the message for subsequent output.

Printer.Print strName, strCourse, strYear

The comma is still used to print values in the same line but at specific print zone.  A print zone occurs every 14 columns on the page.

 

Utilizing the Fonts

Examples:

Printer.FontBold = True

Printer.FontItalic = True

Printer.FontSize = 70

Printer.Print “This text is boldfaced and italicized.”

 

Spacing with Spc() and

Tab()

Examples:

Printer.Print Fname; Spc(10); Lname

The above example prints a 10 spaces between the value of Fname and the value of Lname.

Printer.Print Tab(5), “Total”

The string Total is printed in the 5th column

 

 

Example 1:

Printer.Print “First Page”

Printer.NewPage

Printer.Print “Second Page”

Printer.EndDoc


 

 


Create the following Form.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

When the user clicks on the Print button, the following should be the output:

 

Name:               Racines, Mark

Age:                 4

Level/Section:    Nursery – Blue

 

Write the following procedure:

 

Private Sub Command1_Click()

Printer.FontName = “Arial”

Printer.Print “Name: “;

Printer.FontBold = True

Printer.FontUndeline = True

Printer.Print Tab(2); txtLName.Text & “,” & txtFName.Text

Printer.FontBold = False

Printer.FontUndeline = False

Printer.Print “Age:”; Tab(2); txtAge.Text

Printer.Print “Level/Section:”; Tab(1); cboLevel.Text & “-“ & cboSection.Text

Printer.EndDoc

End Sub

 

 


 

 


Instructions: Create a simple text editor.  The Editor’s interface is as follows:

 

 

 

 

 

 

 

 

 

 

 

When the Print button is clicked, the following dialog box is displayed:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

For the Paper Size ListBox (DropDown ListBox), include three items: Letter, 8 1/2 x 11 in., Legal, 8 1/2 x 14 in., and A4, 210 x 297 mm.  The Color ListBox (DropDown ListBox) contains four colors: Black, Blue, Red, and Green.  Enable this ListBox only when Color Mode (see the Color Mode Frame above) is set to Color. Color refers to the color of the text when printed.

 

When the Print button is pressed, print the text in entered in the previous Form.  Apply print the settings set by the user.  Unload the Form and load the main Form.  Clicking Cancel also invokes back the main Form.

 

 

[ Home ]