Printing in VB

The Basics

Unsurprisingly, Visual Basic provides us with a Printer and Printers object which is available at runtime to all VB apps. The Printers object gives us information about all the available printers installed on the system. The Printer object controls all the output to the active printer, and retrieve information such as the printer name.

First of all, lets look at the basic steps involved in printing in VB. First off, we send all the data we want to print using the Print method. For example, if we wanted to print "Hello", we would call

Printer.Print "Hello"

Each time you call the Print method, your output will move to the next line. So,

Printer.Print "Hello"
Printer.Print "Goodbye!"

would appear as

Hello
Goodbye!

on paper.

If you want to output a new page, you simply call the NewPage method:

Printer.NewPage

Once you have finished outputting the data to the printer, you need to call the EndDoc method:

Printer.EndDoc

Windows will then spool your document to the printer.

You might also like...

Comments

About the author

James Crowley

James Crowley United Kingdom

James first started this website when learning Visual Basic back in 1999 whilst studying his GCSEs. The site grew steadily over the years while being run as a hobby - to a regular monthly audien...

Interested in writing for us? Find out more.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“It is practically impossible to teach good programming style to students that have had prior exposure to BASIC. As potential programmers, they are mentally mutilated beyond hope of regeneration.” - E. W. Dijkstra