?
Solved

Accounting format

Posted on 2012-12-29
4
Medium Priority
?
263 Views
Last Modified: 2012-12-30
I have a message box that puts out 2 lines of currency values (along with text).  

Is there any way to format the currency so it aligns by decimal? (Accountant format)
0
Comment
Question by:thandel
[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
  • 2
4 Comments
 
LVL 18

Expert Comment

by:Jerry Miller
ID: 38730350
0
 
LVL 49

Accepted Solution

by:
Martin Liss earned 2000 total points
ID: 38730367
That won't work because the MsgBox doesn't normally use a monospaced font; in other words each number or letter may be of different widths. It might be possible to subclass the msgbox so that it does use a monospaced font but even if that allowed you to align the decimals with something like this (which doesn't work because of the font problem) it would be ugly because monospaced fonts are IMO ugly.

    Dim Amt1 As String
    Dim Amt2 As String
    Dim FormatString1 As String
    Dim FormatString2 As String
    
    Amt1 = 20000.19
    Amt2 = 5125.12
    
    FormatString1 = "0123456789" ' Initialize string.
    FormatString2 = "0123456789" ' Initialize string.
    
    RSet FormatString1 = Amt1
    RSet FormatString2 = Amt2
    
    Debug.Print FormatString1
    Debug.Print FormatString2
    
    MsgBox FormatString1 & vbCrLf & FormatString2

Open in new window


I think the only choice you have is to accept the ugliness and use a UserForm that contains a label along with this code

Private Sub UserForm_Initialize()
    Dim Amt1 As String
    Dim Amt2 As String
    Dim FormatString1 As String
    Dim FormatString2 As String
    
    Amt1 = 20000.19
    Amt2 = 5125.12
    
    FormatString1 = "0123456789" ' Initialize string.
    FormatString2 = "0123456789" ' Initialize string.
    
    RSet FormatString1 = Amt1
    RSet FormatString2 = Amt2
    
    Debug.Print FormatString1
    Debug.Print FormatString2
    
    Label1.Font = "courier"
    Label1.Caption = "This is ugly but it aligns" & vbCrLf & vbCrLf & FormatString1 & vbCrLf & FormatString2

End Sub

Open in new window


If you do you'll get this:
Ugly but aligned
0
 

Author Closing Comment

by:thandel
ID: 38730721
Thanks for the clear code and example.
0
 
LVL 49

Expert Comment

by:Martin Liss
ID: 38731007
You're welcome and I'm glad I was able to help.

Marty - MVP 2009 to 2012
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

762 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