Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

format function will not right justify 1

Status
Not open for further replies.

rgordley

Programmer
Apr 30, 1999
63
US
Does anyone remember when (at least in Quick Basic PDS) you could do the equivalent of a "printer.print format(number, "###,###.00")" and have the resulting number be right justified with other numbers printed at the same tab? MS documentation (sound of laughter) still maintains that the "#" characters in the format function act as placeholders. In VB 6.0 (at least) they do not. So when sending output directly to the printer without benefit of a data report or the like, how do you right justify numbers??
 
Make a procedure in a module :<br>
<br>
Sub printrechts(positie, bedrag As Currency, formaat As String)<br>
<br>
Dim lengte As Integer<br>
<br>
If formaat = &quot;Currency&quot; Then<br>
Printer.CurrentX = positie - 5<br>
Else<br>
Printer.CurrentX = positie<br>
End If<br>
lengte = Printer.TextWidth(Trim$(Format$(999999999.99, formaat)))<br>
Printer.CurrentX = Printer.CurrentX + lengte - Printer.TextWidth(Trim$(Format$(bedrag, formaat)))<br>
Printer.Print Format$(bedrag, formaat);<br>
<br>
End Sub<br>
<br>
printrechts (Number), &quot;#,###,##0.000 &quot;<br>
<br>
Or<br>
<br>
printrechts (Number), &quot;Currency&quot;<br>
<br>
Success<br>
<br>
Eric<br>
<p>Eric De Decker<br><a href=mailto:vbg.be@vbgroup.nl>vbg.be@vbgroup.nl</a><br><a href= Visual Basic Center</a><br>
 
Thanks for the help, but I already wrote a routine similar to this, the problem is when using proportional fonts...this still does not leave a clean right margin.
 
&gt; the problem is when using proportional fonts...this still does not leave a clean right margin. &lt;<br>
<br>
When sending output to the printer at a high level (like from VB), you have less control over where the text actually ends up. To do this, you have to find out how long the text to be printed is (in printer units), then move the current print location to where you want it right-justified to, then subtract the width of the text. Then print.<br>
<br>
Honestly, it's much easier to specify a fixed-pitch font like Courier. Or use a report tool like Crystal Reports, where they've already done all the work for you.<br>
<br>
Chip H.<br>
<br>

 
thanks chip,<br>
<br>
I wound up using courier in order to get this job done. (what the h*** is a &quot;printer unit&quot;?)<br>
<br>
Didn't want to use CR for 2 reasons.<br>
1. poor portability<br>
2. very simple report (except for this one field)<br>
<br>
M$ always seems to have a better idea. Getting rid of the right justification in the format function is another example of their contact with reality.<br>

 
You could also use the RSET funtion. Something like follows:<br>
<br>
RSet totals = Format(Str(adrive.TotalSize/1024), &quot;###,###&quot;)
 
&gt; (what the h*** is a &quot;printer unit&quot;?)<br>
<br>
Oh, sorry. I'm an old &quot;C&quot; Win api programmer, so sometimes I tend to think at a lower level than VB.<br>
<br>
Printer Units is the resolution the printer is capable of. Equivalent to the pixels used on displays. If you have a high-end laser printer that can do 1800dpi, then on a 11x17 piece of paper, values would run from 0 to almost 30600 (must allow for printable area, which is almost always less than the actual dimensions of the paper). The same in the twips used by VB would go from 0 to almost 2448. This would mean than a 1-twip wide line actually prints a line 12 dots wide. By using printer units, you get much finer degree of control over where your lines go.<br>
<br>
Chip H.<br>
<br>
<br>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top