PRB: Accessing Printer Object's ScaleX, ScaleY Methods Prints Unwanted Page

ID: Q230382


The information in this article applies to:


SYMPTOMS

If you use the ScaleX and ScaleY methods of the Printer Object in Visual Basic version 4.0 (16-bit) you produce an unwanted printed page when running on Windows 95, Windows 98 or Windows NT version 4.0.


CAUSE

The Internal Printer Object code initializes the Printer Object in such a way that a new page is sent to the Printer.


RESOLUTION

ScaleX and ScaleY values can be retrieved through a call to GetDeviceCaps using HORZSIZE and VERTSIZE. The values returned should be converted to the units desired. This will give you the size of the printable area for the Printer's printed page.


Const HORZSIZE = 4
Const VERTSIZE = 6
Const mmTOinches = 25.4

Private Declare Function GetDeviceCaps Lib "GDI" (ByVal hDC%, ByVal nindex%) As Integer

Private Sub Command1_Click()
   Dim iretvalH As Integer, iretvalV as Integer

   ' GetDeviceCaps returns value in millimeters
   iretvalH = GetDeviceCaps(Printer.hDC, HORZSIZE)
   iretvalV = GetDeviceCaps(Printer.hDC, VERTSIZE)

   Print "Height in Inches:", (iretvalV / mmTOinches)
   Print "Width in Inches:", (iretvalH / mmTOinches)
End Sub 


MORE INFORMATION

Starting with Microsoft Visual Basic version 6.0, this behavior is no longer present.

Steps to Reproduce Behavior

  1. Create a new project in Visual Basic 4.0 16-bit Edition.


  2. Place a Command Button (Command1) on Form1.


  3. Paste the following code into the code window.
    
       Private Sub Command1_Click()
          Debug.Print Printer.ScaleX(Printer.Width, vbTwips, vbInches)
          Debug.Print Printer.ScaleY(Printer.Height, vbTwips, vbInches)
       End Sub 


Run the program and click Command1. A blank page will be printed out.


REFERENCES

For additional information about using GetDeviceCaps in the 32-bit version of Visual Basic, please see the following article in the Microsoft Knowledge Base:

Q193943 HOWTO: Use GetDeviceCaps to Determine Margins on a Page

Additional query words: Printer Object ScaleX ScaleY


Keywords          : kbPrinting kbVBp400 
Version           : WINDOWS:4.0
Platform          : WINDOWS 
Issue type        : kbprb 

Last Reviewed: June 2, 1999