This is driving me insane!
Does anyone have a routine that will right justify text on a printer.
I am using the 'Courier New' font which does not appear to be a proportional font but still do not seem to get it right.
In the 'old' DOS days we would say:
@ 0, 80 - Len( cVar1 ) Say cVar1
@ 1, 80 - Len( cVar2 ) Say cVar2
but this does not work in windows.
I have been pulling my hair out the whole morning with this (type) of code:
...
Define Font oFont;
Name 'Courier New';
Size 15, 50
Print oPrn Name 'Report' From User
If Empty( oPrn:hDC )
oPrn:End( )
Return ( NIL )EndIf
oPrn:SetFont( oFont )
nRowStep := oPrn:nVertRes( ) / 66 // 66 rows
nColStep := oPrn:nHorzRes( ) / 80 // 80 cols
oPrn:SetPortrait( )
Page
nRow += nRowStep
oPrn:Say( nRow, ( nColStep * 80 ) - (nColStep * ( Len( 'D' ) ) ), 'D' )
nRow += nRowStep
oPrn:Say( nRow, ( nColStep * 80 ) - (nColStep * ( Len( 'DD' ) ) ), 'DD' )
EndPage
EndPrint
oPrn:End( )
etc. etc.
If you keep repeating the lines above the text 'creeps' to the left.
Any ideas?
Regards,
Dale.
How to right justify text on a printer (Windows)?
- Enrico Maria Giordano
- Posts: 7355
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
Re: How to right justify text on a printer (Windows)?
Have a look at the eighth parameter of TPrinter:Say() method (nPad).
EMG
EMG
- E. Bartzokas
- Posts: 114
- Joined: Tue Feb 14, 2006 8:13 am
- Location: Corinth, Greece
Right Justify to Printer
Try this:
LPAD(myvariable, 12) for character strings
(your variable can be a field name of course, and the number 12 is how many spaces will be added infront of the variable/field.
Same way as it is required to use: Str(nNumber, 12,2) for numbers
I hope I gave you an idea to help you.
Regards
Evans
LPAD(myvariable, 12) for character strings
(your variable can be a field name of course, and the number 12 is how many spaces will be added infront of the variable/field.
Same way as it is required to use: Str(nNumber, 12,2) for numbers
I hope I gave you an idea to help you.
Regards
Evans
- James Bott
- Posts: 4654
- Joined: Fri Nov 18, 2005 4:52 pm
- Location: San Diego, California, USA
- Contact:
Code: Select all
#include "fivewin.ch"
function main()
local oPrn,oFont, nRow:=0,nRowStep:=1,nColStep:=1, aText, I
Print oPrn Name 'Report' preview
If Empty( oPrn:hDC )
oPrn:End( )
Return ( NIL )
EndIf
Define Font oFont;
Name 'Courier New';
Size 15, 10 of oPrn
oPrn:SetFont( oFont )
nRowStep := oPrn:nVertRes( ) / 66 // 66 rows
nColStep := oPrn:nHorzRes( ) / 80 // 80 cols
oPrn:SetPortrait( )
aText:= {"D","very long text","shorter","123456789","cat"}
Page
for I:= 1 to 5
nRow += nRowStep
//oPrn:Say( nRow, ( nColStep * 80 ) - (nColStep * ( Len( "D" ) ) ), "D" )
// Last parameter: 0= left justify, 1= right justify, 2= Center justify
oPrn:Say( nRow, ( nColStep * 20 ),aText[i],,,,,1)
next
EndPage
EndPrint
oPrn:End( )
oFont:end()
return nil
- Enrico Maria Giordano
- Posts: 7355
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
You don't have to issue the latter as it is included in the function called by EndPrint command (PrintEnd()).James Bott wrote:Code: Select all
EndPrint oPrn:End( )
EMG