Re: Best way to print reports ??
When we advance the print line we use a line of code that looks something like this:
Code:
objPrt.CurrentY = ((objPrt.CurrentY + (lngCurFontSize * 20)) \ lngTPY) * lngTPY
lngCurFontSize is set whenever we change fontsize with a line of code like this:
Code:
lngCurFontSize = Int(lngActualFontValue * 1.2)
lngTPY is TWIPSPERPIXELY on the device/printer you are using.
So I guess with all that said we made an assumption that there is 20% fluff space between lines. Four years ago we did a lot of digging around for something more scientific and came up short.
And in reality this has worked real well until about 2 weeks ago when we attempted to print on an old-style pre-printed receipt form for a customer. We could not quite get our lines of print to align with the "pre-printed" stuff on the form.
To get around this I added a new "report object" to my list that would add "twips" between print lines - and adding 35 twips seems to fix it for this particular form.
Keep in mind that you might set a device to fontsize 8 or 10 or 12 but when you look at it in the immediate window/debug.print it will come out to be like 11.8 - there is some interaction between twipsperpixel and fontsize...
As for your other question about how to wrap this - we do our print all in one SUB in a BASMAIN - one call to that SUB (PRINTREPORT or PRINTFORM) will output the entire report - all pages. That might break some coding rules but we went for speed with this. The code is intentionally flat - all one loop - all one CASE statement to drive the report objects. No outside functions or sub calls...
Re: Best way to print reports ??
Re: Best way to print reports ??
Quote:
Originally Posted by szlamany
The code is intentionally flat - all one loop - all one CASE statement to drive the report objects. No outside functions or sub calls...
Wow. That must be some routine.
Thanks for the history lesson, and the pointer on line spacing. Much apreciated szlamany. I can put my ruler and calculator away now ;)
I don't suppose that in your travels you have come across this code snippet...
VB Code:
Sub VertPrint(Target As Object, TextCaption As String, _
FontName As String, Xloc, Yloc, Optional AngleinDeg As Long = 90)
On Error GoTo GetOut
Dim f As LOGFONT
Dim hPrevFont As Long
Dim hFont As Long
Dim FONTSIZE As Integer
FONTSIZE = 10
f.lfEscapement = 10 * AngleinDeg 'rotation angle, in tenths
'FontName = "Arial" + Chr(0) 'null terminated
f.lfFacename = FontName + Chr(0) 'null terminated
If TypeOf Target Is Printer Then
f.lfHeight = (FONTSIZE * -20) / Target.TwipsPerPixelY
Else
f.lfHeight = (FONTSIZE * -20) / Screen.TwipsPerPixelY
End If
hFont = CreateFontIndirect(f)
hPrevFont = SelectObject(Target.hdc, hFont)
Target.CurrentX = Xloc
Target.CurrentY = Yloc
Target.Print TextCaption
' Clean up, restore original font
hFont = SelectObject(Target.hdc, hPrevFont)
DeleteObject hFont
Exit Sub
GetOut:
End Sub
It works firn for screen printing of vertical text - but it comes up short when I try to print vertical text on the printer. I can understand the frig factor needed for the target being Screen or Printer, but I thought that whatever works for the Picturebox works for the Printer, when you use .Print.
The only place it can be falling over is the reference to the Target.hdc. When we are pointing at the printer it is obviously = to Printer. But does the Printer have a .hdc?
Re: Best way to print reports ??
Quote:
Originally Posted by Mark Gambo
Thank you for that Mark. I will file it away for later :thumb:
Re: Best way to print reports ??
That looks a bit like the code snippet in post #9 that I made a couple of days ago...
We've only used the vertical print thing once so far - and I remember it being a pain to get working.
I think we settled on writing the vertical text to a picture box and then using PAINTPICTURE to get it on the printer.
If you get this working without that I'd love to see the code - really would rather do it to the printer directly.
Re: Best way to print reports ??
So you did - I didn't notice it then.
Yes - I though of the picture box aproach, but I would like to be able to do it using Fonts if I can. I will keep you posted on progress.