Solved

How to print with right-to-left aligment

Posted on 2001-07-06
8
896 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

746 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

12 Experts available now in Live!

Get 1:1 Help Now