How to right justify text on a printer (Windows)?

Post Reply
dpaterso
Posts: 142
Joined: Tue Jan 24, 2006 9:45 am
Location: South Africa
Contact:

How to right justify text on a printer (Windows)?

Post by dpaterso »

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.
manuramos
Posts: 219
Joined: Mon Dec 26, 2005 7:25 pm
Location: Jerez de la Frontera (Spain)

Post by manuramos »

RPAD not run efectively in many situations, Try this:

nRightMargin := xxx pixels
oPrn:Say( nTop,nRightMargin-oPrn:GetTextWidth( cText , oFont ),cText,oFont )

You could build a function to only right justify all cTexts. (excuse my english)
Nos Gusta Programar
User avatar
E. Bartzokas
Posts: 114
Joined: Tue Feb 14, 2006 8:13 am
Location: Corinth, Greece

Right Justify to Printer

Post by E. Bartzokas »

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
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Post by James Bott »

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
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Post by Enrico Maria Giordano »

James Bott wrote:

Code: Select all

EndPrint

oPrn:End( )
You don't have to issue the latter as it is included in the function called by EndPrint command (PrintEnd()).

EMG
Post Reply