Solved

How to print with right-to-left aligment

Posted on 2001-07-06
8
897 Views
Last Modified: 2007-11-27
How can I print with right-to-left aligment?
I need to print some senteces with an exact right aligment.

Help me please
0
Comment
Question by:macob
8 Comments
 
LVL 1

Expert Comment

by:ScottNero
ID: 6260967
Print where? On the screen? On a printer? From where? More details required.
0
 
LVL 4

Expert Comment

by:mcoop
ID: 6261024
The most obvious method assuming that you are not using a label control etc...

...is to set the font/size etc for the target print context, then use the .TextWidth(<yourText>) function against that context to find the actual width of <yourText>.

Then - position the target's print cursor with the .CurrentX = <yourRHlimit> - <the width of the text>

then finally .Print <yourText>

Of course you also have to manage the .CurrentY property, and calc/print any other lines that will be positioned above/below.
0
 
LVL 1

Expert Comment

by:ahmadpj
ID: 6261225
If you are using a non-bidirectional windows, mcoop suggestion is good, but if you are using a bidirectional windows (like arabic or hebrew) you can set your printer RightToLeft to True:
Printer.RightToLeft = True
then, the 0,0 point will be in the TopRight of the paper, and your text will be printed with right alignment...
0
 

Author Comment

by:macob
ID: 6261596
I already try using Printer.RightToLeft = True and .TextWidth() but they didnt work.
Could somebody send me an example that works?

Thanks

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 4

Accepted Solution

by:
mcoop earned 110 total points
ID: 6261688
For the money....

Private Sub Form_Load()
 
  Dim textLine(3) As String
 
  textLine(0) = "Welcome to the world"
  textLine(1) = "of right-aligned"
  textLine(2) = "printing"
  textLine(3) = "$ 123.45"
 
  ' (we could use the 'With Printer' block here
  ' - but I wanted to make everything obvious)
 
  Printer.ScaleMode = vbMillimeters ' use whatever you like
  Printer.Font.Name = "Arial"
  Printer.Font.Size = 12
 
  rightMargin = 20 ' your preferred distance from the right edge of the page
  rightlimit = Printer.ScaleWidth - rightMargin  '
 
  Printer.CurrentY = 100  ' approx 4 inches fro top of page
 
  For lNum = 0 To 3
    tWidth = Printer.TextWidth(textLine(lNum))
    Printer.CurrentX = rightlimit - tWidth
    Printer.Print textLine(lNum)  ' no semicolon - will use font's line spacing
  Next
 
  Printer.EndDoc

End Sub
0
 

Author Comment

by:macob
ID: 6261725
Everything works! what means :

' no semicolon - will use font's line spacing

?
0
 
LVL 4

Expert Comment

by:mcoop
ID: 6261823

if you put a semicolon (or comma) after the print statement, the next print statement will execute on the same line as that with the semicolon. (see the Print statement help)

In that case, you would have to manage the vertical placement manually (which you may want to do... for oddball line spacing etc.)

Otherwise, making sure that the print statement ends clean (no semi or comma etc), will ensure that the normal 'line feed' will be inserted as usual following your pinted text - thus you only need to manage the horizontal positioning with .currentX

0
 

Author Comment

by:macob
ID: 6261858
thanks for the help
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now