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



The information in this article applies to:

  • Microsoft Visual Basic Professional Edition, 16-bit, for Windows 4.0, when used with:
    • the operating system: Microsoft Windows NT
    • the operating system: Microsoft Windows 95
    • the operating system: Microsoft Windows 98
  • Microsoft Visual Basic Enterprise Edition, 16-bit, for Windows 4.0, when used with:
    • the operating system: Microsoft Windows NT
    • the operating system: Microsoft Windows 95
    • the operating system: Microsoft Windows 98

This article was previously published under Q230382

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:

193943 HOWTO: Use GetDeviceCaps to Determine Margins on a Page


Modification Type:MajorLast Reviewed:5/13/2003
Keywords:kbprb kbprint KB230382