Sams Teach Yourself Visual Basic 6 in 24 Hours
- Table of Contents
- Copyright
- About the Author
- Acknowledgments
- Introduction
- Who Should Read This Book
- What This Book Will Do for You
- Can This Book Really Teach Visual Basic in 24 Hours?
- What You Need
- Files on the Visual Basic Distribution CD-ROM
- Conventions Used in This Book
- Enough! Time Is Ticking!
- Part I: Introducing Visual Basic
- Hour 1. Visual Basic at Work
- Hour 2.Analyzing Visual Basic Programs
- Hour 3.Controls and Properties
- Hour 4.Examining Labels, Buttons, and Text Boxes
- Part II: Coding the Details
- Hour 5.Putting Code into Visual Basic
- Hour 6.Message and Input Boxes
- Hour 7.Making Decisions
- Hour 8.Visual Basic Looping
- Part III:Putting Code to Work
- Hour 9.Combining Code and Controls
- Hour 10.List Boxes and Data Lists
- Hour 11.Additional Controls
- Hour 12.Dialog Box Basics
- Part IV:Programming with Data
- Hour 13.Modular Programming
- Hour 14.Built-In Functions Save Time
- Hour 15.Visual Basic Database Basics
- Hour 16.Printing with Visual Basic
- Introducing Printing
- Preparing the User for Printing
- Introducing the Printer Object
- The Print Method
- Starting to Print
- Summary
- Q&A
- Workshop
- Part V:Sprucing Up Programs
- Hour 17.Menus and Visual Basic
- Hour 18.The Graphic Image Controls
- Hour 19.Toolbars and More Graphics
- Hour 20.Writing Correct Applications
- Part VI:Advancing Visual Basic Applications
- Hour 21.Visual Basic and ActiveX
- Hour 22.Object Basics
- Hour 23.Distributing Your Applications
- Hour 24.Online Visual Basic
- Part VII:Appendixes
- Appendix A.Operator Precedence
- Appendix B.Answers
- Appendix C.Using the CD-ROM
Preparing the User for Printing
A user could be caught unaware if your application begins printing without first warning him that the printer must be ready. Always remind the user to turn on the printer, make sure that the printer has paper, and ensure that the printer is online, or ready for printing. If the user's printer isn't first turned on and ready with an ample paper supply, the user will receive a Windows print spooler error message similar to the one shown in Figure 16.2.
Figure 16.2 The printer isn't ready.
The function procedure in Listing 16.1 provides you with a useful MsgBox() call that you might want to incorporate into your own programs before printing. Of course, if you use common dialog boxes, you don't have to use this message box because the Print common dialog box serves good notice that printing is about to begin.
Example 16.1. Telling the user about an upcoming print job.
1: Public Function PrReady() As Boolean
2: ' Make sure the user is ready to print
3: Dim intIsReady As Integer
4: intIsReady = MsgBox("Make sure the printer is ready", _
5: vbCritical + vbOKCancel, "Printer Check")
6: If (intIsReady = vbCancel) Then
7: PrReady = False ' A Cancel press returns a False value
8: Else
9: PrReady = True ' User pressed OK so return True
10: End If
11: End Function
Figure 16.3 shows the message box presented by Listing 16.1.
Figure 16.3 The user can now prepare the printer.
After the user reads the message and responds to the message box, the function's return value determines whether the user wants to see the output (assuming that the user has properly prepared the printer for printing) or cancel the printing. The return value of True or False can be checked as follows from another procedure that prints based on the user's response:
If PrReady() Then ' If function is true... Call PrintRoutine ' then print from sub End If
Introducing the Printer Object | Next Section

Account Sign In
View your cart