?
Solved

Print Currency in right alignment

Posted on 1999-11-05
14
Medium Priority
?
356 Views
Last Modified: 2008-03-04
I have a VB6 Developers version where the Data Environment is not fullly developed. So I cannot use the reports object... I need to use the Printer object to print data from an access recordset (from data.control on a form). Some fields are text and boolean and others are currency. The currency should be printed to the Printer Object with right alighnment.
FormatCurrency() gives only left alighned output. What can do? I thought of creating a function which takes the amount and "prints" given amount from right to left. Any other options?
0
Comment
Question by:ulrikehaupt
  • 6
  • 3
  • 2
  • +3
14 Comments
 

Author Comment

by:ulrikehaupt
ID: 2187262
Edited text of question.
0
 
LVL 2

Expert Comment

by:danlevans
ID: 2187278
Is this what you need?

ans$ = "$" & trim(format(urvalue, "##,##0.00")
0
 

Author Comment

by:ulrikehaupt
ID: 2187321
Sorry the #'s do not keep a place open for unused digits (even if Microsoft claims it!). The values go beyond millions at times and the customer wants the amounts printed with cents righ aligned. Whe I use Format(valuestring, "000,000,000.00") I get 0's at the beginning and with #'s the amount aligns left to the $ sign.
Ulrike
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
LVL 5

Expert Comment

by:AnswerTheMan
ID: 2187344
convert it to string. shape the string as you like then send to printer.
0
 
LVL 2

Expert Comment

by:ventond
ID: 2187364
Use the function below just like format
a = "$" & zformat(number, "ZZZ,ZZZ,ZZ0.00")

Public Function ZFormat(vNumber As Variant, sFormat As String) As String
' pvNumber can be any type that the Format() function can accept
'   ie. Integer, Single, String...
' This routine suppresses leading zeros while also leaving column formatting alone
' The VB Format routine '#' char will put nothing instead of space,
' destroying column spacing
    Dim sHold As String
    Dim iLoop As Integer

    sHold = Format$(vNumber, sFormat)
    For iLoop = 1 To Len(sHold)
        If Mid$(sHold, iLoop, 1) = "(" Or Mid$(sHold, iLoop, 1) = " " Then
            iLoop = iLoop + 1
        End If
        If Mid$(sHold, iLoop, 1) <> "0" And Mid$(sHold, iLoop, 1) <> "," Then
            Exit For
        Else
            If iLoop < Len(sHold) And Mid$(sHold, iLoop + 1, 1) = "." Then
                Exit For
            End If
            Mid(sHold, iLoop, 1) = " "
        End If
    Next
    ZFormat = sHold
End Function
0
 
LVL 2

Expert Comment

by:ventond
ID: 2187380
Ooops make that "#"'s instead of "Z"'s.
0
 
LVL 2

Expert Comment

by:ventond
ID: 2187382
Ooops make that "0"'s instead of "Z"'s.

Two mistakes in a row!
0
 

Author Comment

by:ulrikehaupt
ID: 2187412
dear ventond
I'll try this in the morning (It's nearly midnight at my place now.)
I'll come back with the results
Ulrike
0
 
LVL 15

Accepted Solution

by:
ameba earned 400 total points
ID: 2187414
try this in debug window:
?Format$(Format$(1250, "0,000"), "@@@@@@@@@")
?Format$(Format$(1000250, "0,000"), "@@@@@@@@@")
0
 
LVL 12

Expert Comment

by:mark2150
ID: 2187457
Use whatever format you want to build a string:

Printer.CurrentX = rightedgeintwips - Printer.TextWidth(CurrencyString)
Printer.Print CurrencyString

This is will give you right alligned text, formatting issues aside. For columnar work you should be using a monospaced font like Courier New.

M
0
 

Author Comment

by:ulrikehaupt
ID: 2189767
I tried what ameba proposed in the comment above and it works just great.
Such elegant solutions apeal to me.
Ameba, please pass your coment as answer to enable me to get the points to you.
Ulrike
0
 

Author Comment

by:ulrikehaupt
ID: 2189771
An elegant answer.
0
 
LVL 15

Expert Comment

by:ameba
ID: 2189950
Thanks for your points.
0
 

Author Comment

by:ulrikehaupt
ID: 2198483
You're welcome
Ulrike
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…

601 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