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

Printing in columns 1

Status
Not open for further replies.

tcapp

Programmer
Apr 18, 2000
9
US
Hi all,

I am creating a small application to to track addresses. I am trying to print two separate columns of data. I cannot seem to find a good reference on printing. My current code prints straight down the center of the page. Any help would be appreciated.

Current Code:

hwidth = Printer.TextWidth(line1) / 2 ' Get one-half width.
Printer.CurrentX = Printer.ScaleWidth / 2 - hwidth
Printer.CurrentY = Printer.ScaleHeight / 20 - hheight
hheight = Printer.TextHeight(line1) / 20
Printer.Print line1

Printer.FontSize = 12
hwidth = Printer.TextWidth(line2) / 2 ' Get one-half width.
Printer.CurrentX = Printer.ScaleWidth / 2 - hwidth
Printer.Print line2

hwidth = Printer.TextWidth(line3) / 2 ' Get one-half width.
Printer.CurrentX = Printer.ScaleWidth / 2 - hwidth
Printer.Print line3
 
I would get rid of all of that scalewidth / 2 jumble ;)

try this....

printer.currentx = 10
printer.currenty = 10
' Start you off with a decent sized margin...
printer.print line1; tab(10); line2; tab(10); line3


Rob
"Programming is like art...It makes me feel like chopping my ear off."
 
did it help? I like to know these things ;) Rob
"Programming is like art...It makes me feel like chopping my ear off."
 
Yes it did help...it gives me a new line of thinking. Im still rewriting the array...My line1, line2, and line3 are Section, Name, and Address. What I'd like to do is have all three in the same column ie. Section Section
Name Name
Address Address
All the way down the page.
 
no problem...let's say you have three...

dim MySection(1 to ?) as string
dim MyName(1 to ?) as string
dim MyAddress(1 to ?) as string
dim line1 as string
dim line2 as string
dim line3 as string

printer.currentx = 10
printer.currenty = 10

for I = 1 to ubound(mysection)
if I < 2 then
line1 = MySection(I)
line2 = MyName(I)
line3 = MyAddress(I)
else
line1 = line1 & Tab(10) & MySection(I)
line2 = line2 & Tab(10) & MyName(I)
line3 = line3 & Tab(10) & MyAddress(I)
end if
next

printer.print line1
printer.print line2
printer.print line3

Now, you will have a problem if you have too many records...in the case that you do, simply make line1,2, and 3 arrays as well, then....

J = 1
for I = 1 to ubound(mysection)
' Change J every 5 iterations...
if (I Mod 5) = 0 then
J = (I / 5) + 1
end if
if I < 2 then
line1(J) = MySection(I)
line2(J) = MyName(I)
line3(J) = MyAddress(I)
else
line1(J) = line1(J) & Tab(10) & MySection(I)
line2(J) = line2(J) & Tab(10) & MyName(I)
line3(J) = line3(J) & Tab(10) & MyAddress(I)
end if
next

for I = 1 to ubound(line1)
if I < 2 then
printer.print line1(I)
printer.print line2(I)
printer.print line3(I)
else
' Space records by 5's
printer.currentY = printer.currenty + 5
printer.print line1(I)
printer.print line2(I)
printer.print line3(I)
end if
next


Good luck, and if it's helpful, push that link that says it was ;)
Rob
&quot;Programming is like art...It makes me feel like chopping my ear off.&quot;
 
Somewhat different.

Set up your column positions in an array. Set the printer.currentX via the array.


CRUDE example:

Dim ColArray(2) as Single

ColArray(0) = 1.25
ColArray(1) = 4.25

Printer.scale mode = vbInches
Printer.CurrentY = 1.0 'Top Of Form

For Idx = 1 to 2 '2 cols
While Printer.Currenty < Printer.ScaleHeight - 1.25

Printer.CurrentX = ColArray(Idx)
Printer.Print Section

Printer.CurrentX = ColArray(Idx)
Printer.Print Name

Printer.CurrentX = ColArray(Idx)
Printer.Print Address

Printer.Print


'Some type of loop control Here - to get the next sec, name, addr

Wend 'For the page height thinggy
Next Idx 'Move to the 2nd col

MichaelRed
mred@att.net

There is never time to do it right but there is always time to do it over
 
A simple method is to use a fixed-pitch font like Courier. That way you can count column positions and be sure that the data columns will line up.
[tt]
For Each oItem in colItems
printer.print format$(oItem.Number, string$(10, &quot;@&quot;));
printer.print space$(3);
printer.print format$(oItem.Description, string$(30, &quot;@&quot;));
' Right-align value column to paper
printer.print space$(80 - 30 - 3 - 10 - 15);
printer.print format$(oItem.Value, &quot;Currency&quot;)
Next oItem
[/tt]

Chip H.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top