Print Method

See AlsoCYMB7N              Example1OFMJJD>Low

Prints a text string on an object using the current color and font.


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


The Print method has these parts:

Part                           Description


object                         Object (non-MDI form, picture box, Debug, or Printer object) on which expressionlist is to be printed.

Spc(n)                        Name of the Basic function optionally used to insert n spaces into the printed output.  Multiple use is permitted.

Tab(n)                        Name of the Basic function optionally used to tab to the nth column before printing expressionlist.  Multiple use is permitted.

expressionlist             Numeric71RISN or string expressions1330R89 to print.  If omitted, Print 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.  Spc and Tab can also be used with each separate expression.

{ ;|,}                             Character that determines the location of the text cursor for the next character displayed: a semicolon means the cursor is placed immediately after the last character displayed; a comma means the cursor is placed at the start of the next print zone.  Print zones begin every 14 columns.  If neither character is specified, the next character is printed on the next line.  The width of each column is an average of the width of all characters in the point size for the chosen font.


The expressionlist is printed on the object starting at the position indicated by CurrentX and CurrentY properties.

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

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

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

There is no scrolling of lines that cannot fit in the specified position.  The printed string is clipped to fit the object on which it is displayed.

Because the Print method normally prints with proportionally-spaced characters, it is important to remember that there is 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 a "W", occupies more than one fixed-width column, whereas a narrow letter, such as an "i", occupies less.  To account for cases where wider than average characters are used, you must ensure that your tabular columns are positioned far enough apart.  Alternatively, you can print using a fixed-pitch font (such as Courier) to ensure that each character uses only one column.

See Also

CurrentX, CurrentY Properties9TOITD

Printer ObjectCBQUDQ

NewPage Method1UOETVR

PrintForm Method1EMMGHM

Spc FunctionLANSPC

Tab FunctionLANTAB

TextHeight Method4OFKMKO

Print Method Example

The example uses the Print method to display some text on a form.  To try this example, paste the code into the Declarations section of a form.  Then press F5 and click the form.


Sub Form_Click ()

   Dim CX, I, J, K, L, M, Msg, Offset    ' Declare variables.

   Cls                                   ' Clear form.

   Width = 7200                          ' Set form width.

   Height = 5000                         ' Set form height.

   BackColor = QBColor(1)                ' Set background color.

   For I = 1 To 3

      Select Case I

         Case 1                          ' First time.

            ForeColor = QBColor(5)       ' Set foreground color.

            K = 1: L = 9: M = 1

            Msg = "Visual"               ' Set message.

            CX = 0                       ' Set position variable.

         Case 2                          ' Second time.

            K = 1: L = 9: M = 1

            Msg = "Basic"

            CX = ScaleWidth

         Case 3                          ' Third time.

            ForeColor = QBColor(15)

            K = 9: L = 1: M = -1

            Msg = "Visual Basic"

            CX = ScaleWidth / 2

      End Select

      For J = K To L Step M

         Select Case J                   ' Change font size.

            Case 1: Fontsize = 8

            Case 2: Fontsize = 10

            Case 3: Fontsize = 12

            Case 4: Fontsize = 14

            Case 5: Fontsize = 18

            Case 6: Fontsize = 20

            Case 7: Fontsize = 24

            Case 8: Fontsize = 36

            Case 9: Fontsize = 48

         End Select

         If I = 1 Then

            Offset = 0                   ' Text on left.

         ElseIf I = 2 Then

            Offset = TextWidth(Msg)      ' Text on right.


            Offset = TextWidth(Msg) / 2  ' Text in center.

         End If

         CurrentX = CX - Offset

         Print Msg                       ' Print message.

      Next J

      CurrentY = 0                       ' Reset to top of form.

   Next I

End Sub