Link to home
Start Free TrialLog in
Avatar of PoRL
PoRL

asked on

Printing in columns

I'm trying to print a series of columns of data out, only I'm having a few problems.

I first tried using something like:
dummy$=field1$+field2$+..
printer.print Dummy$

The problem was that the non-uniformity in the physical print size of the various fields (even though they were all the same character width) meant that things didn't line up correctly.

I then tried loading the various columns into list boxes on a new form, and then used:
formname.printform

I got an error message telling me that my printer "didn't support rastering" (I'm using an Epsom Stylus 740, under Win98 with VB6)

The documentation that came with VB6 is blummin' terrible (I'm sure it's OK if you already know what you're doing), so any help would be greatly appreciated...

PoRL
Avatar of mcrider
mcrider

Have you tried the tab() function??

Something like:

dummy$=field1$+field2$+..
printer.print field1$; Tab(10); field2$; Tab(40); field3$



Cheers!



That's bizzare... I never typed "dummy$=field1$+field2$+.." in my response above, yet it showed up... Expert's exchange acting up again??? Anyhow, my answer should have looked like this:


Have you tried the tab() function??

Something like:

printer.print field1$; Tab(10); field2$; Tab(40); field3$



Cheers!
ASKER CERTIFIED SOLUTION
Avatar of mark2150
mark2150

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
There is ABSOLUTELY NOTHING wrong with using TAB function.  It is NOT unreliable.  It is a standard function that you can EASILY use to print columns.

Here is the help page from Microsoft on the Tab Function:





TAB Function
------------

Used with the Print # statement or the Print method to position output.

Syntax

Tab[(n)]

The optional n argument is the column number moved to before displaying or printing the next expression in a list. If omitted, Tab moves the insertion point to the beginning of the next print zone. This allows Tab to be used instead of a comma in locales where the comma is used as a decimal separator.

Remarks

If the current print position on the current line is greater than n, Tab skips to the nth column on the next output line. If n is less than 1, Tab moves the print position to column 1. If n is greater than the output line width, Tab calculates the next print position using the formula:

n Mod width

For example, if width is 80 and you specify Tab(90), the next print will start at column 10 (the remainder of 90/80). If n is less than the current print position, printing begins on the next line at the calculated print position. If the calculated print position is greater than the current print position, printing begins at the calculated print position on the same line.

The leftmost print position on an output line is always 1. When you use the Print # statement to print to files, the rightmost print position is the current width of the output file, which you can set using the Width # statement.

Note   Make sure your tabular columns are wide enough to accommodate wide letters.

When you use the Tab function with the Print method, the print surface is divided into uniform, fixed-width columns. The width of each column is an average of the width of all characters in the point size for the chosen font. However, there is no correlation between the number of characters printed and the number of fixed-width columns those characters occupy. For example, the uppercase letter W occupies more than one fixed-width column and the lowercase letter i occupies less than one fixed-width column.
Avatar of PoRL

ASKER

The final paragraph seems to be the problem. I don't know (obviously) exactly what data will be put into the thing. It might be "Wu" and "Popadopolous"..

mark2150 suggests that the printer.textwidth might be useful in determining the *maximum* with of text in a column (if I loop through all of the data entries), but is there anyway to use that information to set the TAB(n) function correctly??

Finally, does anybody have any ideas why PrintForm doesn't work?? It's not as if my Epsom is an old printer..

PoRL
The final paragraph is indeed why TAB is "unreliable". This is especially true if you're trying to right align text. The statement:

Printer.Print Tab(80 - len(MyString); Mystring

Which will produce nice right aligned stuff under DOS with a monospaced printer font, will completely mess up under windows using proportional fonts.

If you want nicely aligned columns as the text width wanders around, my method is much superior to TAB().

PoRL, the TextWidth property will determine the width of *any* item. You don't have to search for the maximum. When you implement my loop as shown, it will properly right align all values in 'Field3'

As for printform, this is not a really good way to generate printouts. It's basically the equivalent of doing an <Alt/Prt Sc> where you'ld screen dump to the printer under DOS. This will produce an image of the screen, but the size will not be consistent on systems with different screen or printer resolutions. Say your printer prints at both 300 DPI and 600 DPI, you get it looking nice at 300 DPI and then your user switches to 600 and the printout shrinks to 1/4 the area! Not good.

M
Avatar of PoRL

ASKER

I couldn't get the "Tab()" to do what I wanted at all, so used mark2150's method of "positioning" the printhead, so I'm afraid (mcrider) he gets the points.

Incidentally, the only problem I had was setting the scale of the thing correctly using printer.ScaleMode. I tried setting this to 6 (i.e. millimeters) but what should have been a 10mm increase in width turned out to about about 13mm! Although I couldn't suss out why this was, I was able to adjust my column widths so everything came as I wanted.

Thanks for your help!


PoRL
Don't use the .ScaleMode. If you just set the .Scale to whatever units you like then .ScaleMode will automatically change to "user".

I'm not sure the exact size of A4 paper, but it's around 212mm wide by 275mm high. So you could set the .Scale to (0,0)-(200,267) and then instead of Col1 = 1, Col2=4 and Col3 = 8 you could have Col1=25, Col2 = 100 and Col3=200 and all would work same-same.

M