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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

printing using VB 3

Status
Not open for further replies.

Painkiller

Programmer
May 18, 2001
97
NL
Hi,

I'm trying to print from a program, but for some reason I can't get good results from the printer.

I'm trying to print string s followed by numbers. something like this:

printer.print "Lease costs: " & sngLeaseCosts
printer.print "Car value: " & sngCarValue

with several similar lines beneath each other.
I'm using spaces in the string to make sure that the numbers are displayed right above each other. However, when I print, the result looks something like this:

Lease Costs: 1400
Car value: 40000

What gives? Why aren't the numbers printed right beneath each other?
Hope somebody can help me

Sujesh
 
Printing is a bit of a nightmare with VB. The easiest way is to print through Word. However, good results can be obtained through the printer object.

The reason your text is not lining up is because of the font you are using. You are probably printing with a true type font, so each character has only the width it needs to be (for example an i has a smaller width than a w). If you use a system font (such as this font in this message) each character has the same width. If you use this you will be able to line the text up with spaces.

An alternative is to use trial and error with vbTab, you will then be able to line the text up. Another way is to use the Printer.CurrentX value and set up columns (this is very difficult and takes a long time).

My suggestion would be to use vbTab between the text, or if you have time to use Word.

Madlarry
 
thanks madlarry for yor reply, it's helpful.

I want to try to print using a system font, however, I don't know the names of such fonts, can you tell me the name of such a font (e.g. a truetype font would be "arial" ) or where I might find the names?

Sujesh
 
Sujesh,

I usually use Courier New. It is a system font and has a fairly standard appearance.

Tim
 
printer.fonts tell you how many fonts there are and printer.font(no) tells you the font; you can use this to populate a cbo box.

Have you tried setting the currentx before printing the variable so that they line up??
 
My thanks to everybody for their responses. The problem is now solved by specifying a system font with the line:

Printer.Font = "Courier (W1)" 'selecting courier as a font

Sujesh
 
Painkiller,

While they 'do' provide the capability of adjusting the position of fields for alignment, the 'system' fonts are generally un-attractive. A MUCH better and (at least for me) ultimately easier approach is to layout the printer reports using whatever font is 'best' for the report. Then set up an array of X-Y values for the location of each item to print. For each element to be printed, reference the array and set Printer.CurrentX and Printer.CurrentY to the values in the array. You can/will need to work at this - at least for the first few reports - as there are some instances where the value needs to depend on the current value. An example would be doing the detail lines on a 'ledger' type of report, where you simply want to do a standard line feed type of positioning. You also need to keep track of the vertical position (printer.currenty), to be sure you have sufficient space to print your page footer, issue the printer.newpage (formfeed), and printer the (next) page header before continuing with the detail(s) or following page(s).

MichaelRed
redmsp@erols.com

There is never time to do it right but there is always time to do it over
 
For this, print the numeric value on a fixed Print.CurrentX with Format$(Variable, "@@@@@@@@@@@@@@")
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top