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

Building Print line 4

Status
Not open for further replies.

PoppapumpJ

Programmer
Dec 17, 2001
86
0
0
US
I am looping through a flex grid to generate a report.

For every cell in a row I have been using this line
Printer.Print .Text & vbTab;



the row builds fine, but I need to be align the columns. I have tried this:
Printer.Print .Text & Space(7 - Len(.Text))

that seems like it would space everything correctly, but instead it starts writing the next column on the next line. Leaving the vbTab; at the end does continue the line but throws off the allignment.


Any suggestions on how to make a line contine without using vbTab;


here is my entire code
Limits have been set to prevent printing the entire report, thus saving time and paper.


With grdMain ' Flex grid with data
For introw = 0 To 10 'intRecCount ' Loop for each line to print.
.Row = introw ' Set flex grid row.

.Col = 9
If .Text = CLIENT_ROW Then
Printer.FontBold = True
Else
Printer.FontBold = False
End If

Printer.Print Space(3);

'print column 1
.Col = 0
Printer.Print .Text & Space(7 - Len(.Text)) & vbTab;

For intcol = 1 To grdMain.Cols - 1 ' Last col var previously set
.Col = intcol ' Set flex grid Column.
Printer.Print .Text & vbTab;
Next
Printer.Print
Next
End With

Printer.EndDoc




thanks
 
Using the Space() function will only work if you are using fixed width fonts, like Courier.

One approach to aligning columms when using the Printer object is to position to the print head using the Printer.CurrentX and Printer.CurrentY properties.

Figure out the proper X coordinate for each column, with that coordinate being the left edge of left-justified columns, the actual center for centered columns and the right edge for right-justified columns.

When is comes to the actual printing --

For Left Justified Columns
Code:
Printer.CurrentX = <Col location>
Printer.Print .Text
For Centered Columns
Code:
Printer.CurrentX = <Col Location> - (Printer.TextWidth (.Text) / 2)
Printer.Print .Text
For Right Justified Columns
Code:
Printer.CurrentX = <Col Location> - Printer.TextWidth (.Text)
Printer.Print .Text
Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Instead of using the vbTab and spaces, the Printer object has it's own Tab feature that you can create your own columns with it. Using your code, try this:

Printer.Print .Text & Tab(7 - Len(.Text))

This will start every column at the same spot. You may to play with the size a little bit to get it to look like exactly like you want, but that should help you out.
 
You say:
< I have tried this:
Printer.Print .Text & Space(7 - Len(.Text))

that seems like it would space everything correctly, but instead it starts writing the next column on the next line. Leaving the vbTab; at the end does continue the line but throws off the allignment. >

You appear to have missed the semicolon <;> off the end of the line. The semicolon is the signal for print position to stay on the same line
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top