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
PoRLAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

 
mcriderCommented:
Have you tried the tab() function??

Something like:

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



Cheers!



0
 
mcriderCommented:
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!
0
 
mark2150Commented:
Tabbing is fairly unreliable.

Although somewhat complex, Printer.CurrentX/Y is best way to handle. Use the printer.Scale command to set the dimensions of the logical printer to match your physical paper printable area. Then use the printer.CurrentX and Y commands to move the print cursor to exactly where you want it. You can then print in a proportional font and even do nice things like right align or center. Here is a sample print routine (off the top of my head:

Const Col1 as Double = 1.0 ' Left aligned col location
Const Col2 as Double = 4.0 ' Center aligned col location
Const Col3 as Double = 8.0 ' Right aligned col location
Dim OldY as Double ' Position down from top
Dim Work as String ' Working String
'
Printer.Scale (0,0)-(8,10.5) ' 8-1/2x11 less 1/4" all round for printable region
'
' Assuming you have gotten database recordset open at this point
'
do while not rs.eof
  oldy = printer.currenty
  printer.currentx = col1
  printer.print rs!field1 ' Left aligned
'
  Printer.CurrentY = oldy
  work = trim("" & RS!field2) ' Get 2nd fields data into a var
  printer.CurrentX = col2 - (printer.TextWidth(work)/2) 'Position to center
  Printer.Print work
'
  Printer.CurrentY = oldY
  work = trim("" & RS!Field3) ' 3rd field
  Printer.CurrentX = col3 - printer.textwidth(work)
  Printer.Print Work ' Right aligned
'
  RS.MoveNext  ' Advance to next record
Loop
'
Printer.EndDoc

This will give you a nice three column layout. Is the "right" way to print under VB. Using SPACE() or TAB() is hangover from DOS and will produce erratic results as users change fonts/printers. By using absolute positioning, no matter what printer or font is selected print positions will come out *exactly* the same.

M
0

Experts Exchange Solution brought to you by ConnectWise

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
mcriderCommented:
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.
0
 
PoRLAuthor Commented:
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
0
 
mark2150Commented:
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
0
 
PoRLAuthor Commented:
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
0
 
mark2150Commented:
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
0
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.

All Courses

From novice to tech pro — start learning today.