ulrikehaupt
asked on
Print Currency in right alignment
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?
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?
Is this what you need?
ans$ = "$" & trim(format(urvalue, "##,##0.00")
ans$ = "$" & trim(format(urvalue, "##,##0.00")
ASKER
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
Ulrike
convert it to string. shape the string as you like then send to printer.
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
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
Ooops make that "#"'s instead of "Z"'s.
Ooops make that "0"'s instead of "Z"'s.
Two mistakes in a row!
Two mistakes in a row!
ASKER
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
I'll try this in the morning (It's nearly midnight at my place now.)
I'll come back with the results
Ulrike
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Use whatever format you want to build a string:
Printer.CurrentX = rightedgeintwips - Printer.TextWidth(Currency String)
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
Printer.CurrentX = rightedgeintwips - Printer.TextWidth(Currency
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
ASKER
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
Such elegant solutions apeal to me.
Ameba, please pass your coment as answer to enable me to get the points to you.
Ulrike
ASKER
An elegant answer.
Thanks for your points.
ASKER
You're welcome
Ulrike
Ulrike
ASKER