The code below shows four types of justification when printing.
left
right
centred
centred in a given column width, at a given position
left in a given column width, at a given position
centred in a given column width, at a given postion It does not take into consideration:
1. text wider than the print area
2. optimization for speed
Will work with most font sizes except very large fonts.
Dim Txt As String
Dim ColPos As Long
Dim ColWidth As Long
Me.Cls
' 1. Left justify
Txt = "Left"
Me.CurrentX = 0
Me.Print Txt
' 2. Right justify on form
Txt = "Right"
Me.CurrentX = Me.ScaleWidth - Me.TextWidth(Txt)
Me.Print Txt
' 3. Centre on form
Txt = "Centred on form"
Me.CurrentX = (Me.ScaleWidth - Me.TextWidth(Txt)) 2
Me.Print Txt
' 4. Right justify in a given width, at a given column.
Txt = "Right in col"
ColPos = Me.ScaleWidth 4
ColWidth = Me.ScaleWidth 4
Do Until Me.TextWidth(Txt) < ColWidth
' Make sure the text fits in the column.
Txt = Right$(Txt, Len(Txt) - 1)
Loop
Me.CurrentX = ColPos + (ColWidth - Me.TextWidth(Txt))
Me.Print Txt
' 5. Left justify in a given width, at a given column.
Txt = "Left in col"
Do Until Me.TextWidth(Txt) < ColWidth
' Make sure the text fits in the column.
Txt = Left$(Txt, Len(Txt) - 1)
Loop
Me.CurrentX = ColPos
Me.Print Txt
' 6. Centred in a given width, at a given column.
Txt = "Centred in col"
Do Until Me.TextWidth(Txt) < ColWidth
' Make sure the text fits in the column.
Txt = Left$(Txt, Len(Txt) - 1)
Loop
Me.CurrentX = ColPos + (ColWidth - Me.TextWidth(Txt)) 2
Me.Print Txt
' Block the column to view justification of 4 and 5.
Me.Line (ColPos, 0)-(ColPos + ColWidth, Me.ScaleHeight - 10), , B
|