Alignment and Numaric Format when printing

Posted on 2002-06-23
Medium Priority
Last Modified: 2010-05-02
Hi experts

I have problem when printing in VB. I can not format the currancy data with two default decimal place like

1,230.00   this .00 is not coming
2,000.50   this are coming automatically.

At thesame time i also want make right allingment of all the currency records.

Thank u

Question by:sumantachandra
  • 3

Expert Comment

ID: 7101555
If u mean you can't format the number, then use this:
MsgBox Format(number, "###,###.00")

If you mean you can't print the formatted number, then I suggest you change the number after formating it to a string by using str(number), and print the string.

>At thesame time i also want make right allingment of all the currency records.

Could u explain it in more details ?

thank u,

LVL 75

Expert Comment

by:Anthony Perkins
ID: 7102348
In addition to egsemsem's comment, to get the numbers to right align in a text format such as NotePad use the following:

Const NUM_MASK = "###,##0.00"
Dim Str_Mask As String

Str_Mask = String(Len(NUM_MASK), "@")
Debug.Print Format$(Format$(1.23, MASK), StrMask)
Debug.Print Format$(Format$(12.34, MASK), StrMask)
Debug.Print Format$(Format$(123.45, MASK), StrMask)
Debug.Print Format$(Format$(1234.56, MASK), StrMask)

LVL 75

Expert Comment

by:Anthony Perkins
ID: 7102352
Sorry, but here is the corrected version:

Const NUM_MASK = "###,##0.00"
Dim Str_Mask As String

Str_Mask = String(Len(NUM_MASK), "@")
Debug.Print Format$(Format$(1.23, NUM_MASK), Str_Mask)
Debug.Print Format$(Format$(12.34, NUM_MASK), Str_Mask)
Debug.Print Format$(Format$(123.45, NUM_MASK), Str_Mask)
Debug.Print Format$(Format$(1234.56, NUM_MASK), Str_Mask)


Author Comment

ID: 7104547
hi experts.

i'm heighly oblized to all of u for the effort. but i'm still confused. i think i should brife my problem in perticular.

i have a sales table and i want bill / invoice printing.
my db connections are ok. but perticularly i cannot geting desire result when printing currancy filed like as follows

Item           Rate             qty            Total
LUX            120               2              240
MUX            100.50            3              301.50
KUX            30                3              90

i want these rate and total column should be right alligned, these 120 or 30 must be coming like 120.00 , 30.00.

i am using hard way printing useing printer.print methode for printing.

I hope u can understand what exactly i want.

Expecting u'r valuable ans.


LVL 75

Accepted Solution

Anthony Perkins earned 800 total points
ID: 7104671
Two separate issues:
In order to get decimals use something like:
Printer.Print Format$(120, "###,##0.00")

In addition, if you want to right align use something like:
Printer.Print Format$(Format$(120, "###,##0.00"), "@@@@@@@@@@")

This last is assuming a non-proportional font such as courier, for proportional fonts, it is less trivial.


Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

624 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