Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to print with right-to-left aligment

Posted on 2001-07-06
8
Medium Priority
?
908 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
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…
Suggested Courses

610 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