Solved

How to print with right-to-left aligment

Posted on 2001-07-06
8
900 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

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
 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

860 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