Lesson 39: Printing in VB6
Master the Printer object to create professional printed output from your VB6 applications
Lesson Overview
Key Takeaway
The Printer object in VB6 provides powerful capabilities to send output directly to printers, allowing you to create professional documents, reports, and printed forms from your applications.
Welcome to Lesson 39 of our Visual Basic 6 Tutorial! In this lesson, you'll learn how to use the Printer object to send output directly to printers, format your printed documents, and create professional printed materials from your VB6 applications.
39.1 Understanding the Printer Object
VB6 provides a built-in Printer object that allows your applications to send output directly to printers. This object has several key methods and properties:
Print Method
Sends text to the printer, similar to how Print works for forms
NewPage
Starts a new page in the current print job
EndDoc
Sends the entire document to the printer
VB6 Code
Create output using Printer object
Print Spool
Document is queued for printing
Printer
Physical document is printed
Basic Printing Example
The simplest way to print from VB6 is to use the Printer object with the EndDoc method:
Private Sub Form_Load()Printer.Print "Welcome to Visual Basic"Printer.EndDocEnd Sub
Important
Always include Printer.EndDoc to actually send your document to the printer. Without it, your output will only be sent to the print spooler when the application terminates.
Printing Variables and Calculations
You can print variables and calculated values just like you would display them on a form:
Private Sub Command1_Click()Dim x, y As String, z As Variantx = InputBox("Enter the first Number")y = InputBox("Enter the second Number")z = Val(x) + Val(y)Printer.Print "The answer is " & zPrinter.EndDocEnd Sub
Printing Text File Contents
You can easily print the contents of a text file or text box:
Private Sub CmdPrint_Click()Printer.Print Text1.TextPrinter.EndDocEnd Sub
39.2 Formatting Printed Output
The Printer object provides several properties to format your printed output:
Font Properties
FontName, FontSize, FontBold, FontItalic, and FontUnderline allow you to control text appearance
Positioning
CurrentX and CurrentY properties control where the next output will appear
Page Management
NewPage method starts a new page, Page property tracks current page number
Text Formatting
ScaleWidth and ScaleHeight properties help with positioning elements
Formatting Example
This example demonstrates how to format printed text:
Private Sub CmdPrintFormatted_Click()' Set font propertiesPrinter.FontName = "Verdana"Printer.FontSize = 16Printer.FontBold = TruePrinter.FontItalic = TruePrinter.FontUnderline = True' Print centered titlePrinter.CurrentX = (Printer.ScaleWidth - Printer.TextWidth("Report Title")) / 2Printer.Print "Report Title"' Reset formatting for bodyPrinter.FontBold = FalsePrinter.FontItalic = FalsePrinter.FontUnderline = FalsePrinter.FontSize = 10' Print contentPrinter.Print "This is a formatted report generated from VB6"Printer.Print "Printed on: " & Format(Date, "Long Date")' Add page numberPrinter.CurrentY = Printer.ScaleHeight - 500Printer.Print "Page " & Printer.PagePrinter.EndDocEnd Sub
Preview of Formatted Output
Report Title
This is a formatted report generated from VB6
Printed on: June 15, 2023
Printing Multiplication Table
This example uses nested loops to print a multiplication table:
Private Sub Command1_Click()Dim i, j As IntegerFor i = 2 To 9For j = 2 To 9Printer.Print i & "x" & j & " =" & i * jNext jPrinter.Print ' Print blank lineNext iPrinter.EndDocEnd Sub
Lesson Summary
In this lesson, you've learned how to use the Printer object to create printed output from your VB6 applications:
Printer Object Basics
Using the Print method and EndDoc to send output to printers
Formatting Techniques
Controlling font properties, positioning, and page management
Practical Examples
Printing variables, calculations, text files, and formatted reports
Advanced Techniques
Using loops to generate complex printed output like tables
Pro Tip
For more complex printing needs, consider using the Printer object in combination with the PrintForm method to capture the current form state, or third-party reporting tools for advanced report generation.
Next Lesson
Continue your VB6 journey with Lesson 40: Report Creation where you'll learn to create professional database reports.
Related Resources
Visual Basic 6 Made Easy
Start your programming journey with Visual Basic 6. Learn how to build Windows applications step-by-step using an easy and beginner-friendly approach.
- Perfect for beginners
- Learn core programming concepts
- Build real VB6 applications
Visual Basic 2026 Made Easy
Upgrade to modern Visual Basic with VB.NET, .NET 10, and Visual Studio 2026. Build real-world applications with modern tools and AI-powered development.
- Modern VB.NET development
- Hands-on projects and real apps
- GitHub Copilot & AI integration
๐ Ready for the Next Level?
After learning the basics with VB6 Made Easy and upgrading to VB2026 Made Easy, continue your journey into advanced professional development.
Advanced VB.NET Programming
Take your VB.NET skills to the next level. Learn advanced programming techniques, real-world architectures, and professional development practices using modern .NET.
Best For:
- After VB6 or VB.NET fundamentals
- Intermediate to advanced learners
- Developers building real-world systems
๐ Migrating from VB6 to VB.NET
Still using or learning classic Visual Basic 6? This practical step-by-step guide shows you how to migrate legacy VB6 applications to modern VB.NET with Visual Studio 2026 and .NET 10.
VB6 to Modern VB.NET Made Easy
A practical step-by-step guide to migrating legacy Visual Basic 6 applications to VB.NET with Visual Studio 2026 and .NET 10.
- Designed for VB6 programmers and legacy app maintainers
- Clear migration guidance from classic VB to modern .NET
- Perfect bridge between VB6 fundamentals and VB.NET development
๐ Move to Modern VB.NET
Visual Basic 6 is your foundation โ but modern development uses VB.NET with .NET and Visual Studio 2026.
Start VB.NET Tutorial โ