Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printer Object & Text Width

Status
Not open for further replies.

Skittle

ISP
Sep 10, 2002
1,528
US
I have a problem regarding the Printer object.

I have a simple line of code that prints a string on the left hand side of a page, a title in the centre and another string right jutified.

To right justify the third string I have identified the
width of the text using the Printer.Textwidth(string)
method. Trouble is, it doesn't work even though my VB book says it does. The right justified string is truncated
at the edge of the page, in other words the X position is to far to the right.

The code is as follows but I don't get why it isn't working.

Printer.FontName = "Courier New"
Printer.FontSize = "12"
Printer.Print vbCrLf
Printer.Print "Left justified String";

'
' Title Centered
Printer.FontUnderline = True
strMyLine = "My Header"
Printer.CurrentX = Printer.Width / 2
Printer.CurrentX = (Printer.CurrentX - _
Printer.TextWidth(strMyLine) / 2)
Printer.Print strMyLine;
Printer.FontUnderline = False

'
' Right Justified
strMyLine = "12345678901234567890"
Printer.CurrentX = Printer.Width - _
Printer.TextWidth(strMyLine)
Printer.Print strMyLine;
Printer.EndDoc


The right justified text is printed as '123456789012345'
missing the last '67890'.

Wierd.







Dazed and confused
 
Try using Printer.ScaleWidth instead of Printer.Width.
ScaleWidth takes into account the fact that most laser printers cannot print to the edge of the paper.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top