Print Method

Applies To

Debug object, Report object.

Description

The Print method prints text on a Report object using the current color and font.

Syntax

object.Print [{Spc(n) | Tab(n)}][expressionlist][{;|,}]

The Print method has the following arguments.

Argument

Description

object

The Report object on which the text is to be printed.

Spc(n)

The Visual Basic function used to insert n spaces into the printed output. Multiple use is permitted.

Tab(n)

The Visual Basic function used to move the insertion point to the nth print zone before the expressionlist argument is printed. Print zones begin every 14 columns. The width of each column is an average of the width of all characters in the font size for the chosen font. Multiple use is permitted.

expressionlist

The numeric or string expressions to print. If this argument is omitted, the Print method prints a blank line. Multiple expressions can be separated with a space, a semicolon (;), or a comma. A space has the same effect as a semicolon. You can also use the Spc and Tab functions to separate each pair of expressions.

{;|,}

Determines the location of the insertion point for the next character printed. A semicolon means that the insertion point is placed immediately after the last character printed; a comma means that the insertion point is placed at the start of the next print zone.


Remarks

You can use this method only in a event procedure or macro specified by a section's OnPrint event property setting.

The expressions specified by the expressionlist argument are printed on the object starting at the position indicated by the CurrentX and CurrentY property settings.

When the expressionlist argument is printed, a carriage return is usually appended so that the next Print method begins printing on the next line. When a carriage return occurs, the CurrentY property setting is increased by the height of the expressionlist argument (the same as the value returned by the TextHeight method) and the CurrentX property is set to 0.

When a semicolon follows the expressionlist argument, no carriage return is appended, and the next Print method prints on the same line that the current Print method printed on. The CurrentX and CurrentY properties are set to the point immediately after the last character printed. If the expressionlist argument itself contains carriage returns, each such embedded carriage return sets the CurrentX and CurrentY properties as described for the Print method without a semicolon.

When a comma follows the expressionlist argument, the CurrentX and CurrentY properties are set to the next print zone on the same line.

When the expressionlist argument is printed on a Report object, lines that can't fit in the specified position don't scroll. The text is clipped to fit the object.

Because the Print method usually prints with proportionally spaced characters, it's important to remember that there's no correlation between the number of characters printed and the number of fixed-width columns those characters occupy. For example, a wide letter (such as W) occupies more than one fixed-width column, whereas a narrow letter (such as I) occupies less. You should make sure that your tabular columns are positioned far enough apart to accommodate the text you wish to print. Alternately, you can print with a fixed-pitch font (such as Courier) to ensure that each character uses only one column.

See Also

CurrentX, CurrentY properties, FontBold property, FontItalic, FontUnderline properties, FontName, FontSize properties, Scale method, ScaleHeight, ScaleWidth properties, ScaleLeft, ScaleTop properties, ScaleMode property.

Example

The following example uses the Print method to display text on a report named Report1. It uses the TextWidth and TextHeight methods to center the text vertically and horizontally.

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    Dim rpt As Report
    Dim strMessage As String
    Dim intHorSize As Integer, intVerSize As Integer

    Set rpt = Me
    strMessage = "DisplayMessage"
    With rpt
        'Set scale to pixels, and set FontName and FontSize properties.
        .ScaleMode = 3
        .FontName = "Courier"
        .FontSize = 24
    End With
    ' Horizontal width.
    intHorSize = Rpt.TextWidth(strMessage)
    ' Vertical height.
    intVerSize = Rpt.TextHeight(strMessage)
    ' Calculate location of text to be displayed.
    Rpt.CurrentX = (Rpt.ScaleWidth/2) - (intHorSize/2)
    Rpt.CurrentY = (Rpt.ScaleHeight/2) - (intVerSize/2)
    ' Print text on Report object.
    Rpt.Print strMessage
End Sub