|
-
Oct 15th, 2003, 02:26 PM
#1
Thread Starter
Frenzied Member
[RESOLVED] print out a list of text...
how do i print out a long list of data...
i know i need to use the printer. function.. but if i say have an sql query like: select Car, make, model, reg_num from table1
i want to print it out on the paper like:
Car & tab & make & tab & model & tab & reg_num
the header needs to have something like:
Avail Car's centered, and the date right aligned,
how do i do this?
thanks ppl
-
Oct 15th, 2003, 02:34 PM
#2
Look up the Tab() and Space() functions in VB.
The Tab() function will position the text to be printed at the
column you specify.
The two function will help you generate a formatted text report.
Although you may need to use an font that is evenly sized like Courier.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Oct 19th, 2003, 09:44 AM
#3
Thread Starter
Frenzied Member
hey ya,
I haven't actually used the Printer. functions before, so im like totally lost as to how to go ahead with this...
what i need is simular to the thread here:
http://www.vbforums.com/showthread.p...1&referrerid=0
Any code samples of how to use the printer. code's would be great, if ne 1 has any...
thanks.
-
Oct 19th, 2003, 12:31 PM
#4
Hyperactive Member
this may sound stupid.. but why not.. do the formatin using a rich text box.. and.. print it..
-
Oct 19th, 2003, 03:17 PM
#5
Fanatic Member
Well here is one simple way of doing it using one of my old print functions that I just dug up. There are better ways of doing it but I think this would suffice for you.
VB Code:
Private Sub PrintLine(ColOne As String, ColOnePos As String,_
ColTwo As String, ColTwoPos As String, ColThree As String,_
ColThreePos As String, ColFour As String, ColFourPos As String,_
ColFive As String, ColFivePos As String, ColSix As String, ColSixPos As String)
If ColOnePos <> "" Then
Printer.CurrentX = ColOnePos
Printer.Print ColOne;
If ColTwoPos <> "" Then
Printer.CurrentX = ColTwoPos
End If
Printer.Print ColTwo;
If ColThreePos <> "" Then
Printer.CurrentX = ColThreePos
End If
Printer.Print ColThree;
If ColFourPos <> "" Then
Printer.CurrentX = ColFourPos
End If
Printer.Print ColFour;
If ColFivePos <> "" Then
Printer.CurrentX = ColFivePos
End If
Printer.Print ColFive;
If ColSixPos <> "" Then
Printer.CurrentX = ColSixPos
End If
Printer.Print ColSix;
End If
Printer.Print
End Sub
Then to use this function for example the Avail's Cars centered
You'd have to first setup the printer's Scale
VB Code:
Printer.ScaleMode = VbCentimeters 'The one I commonly use
Then you would print your first line
VB Code:
PrintLine "Avails Cars", (Printer.ScaleWidth / 2) - (Printer.Textwidth("Avails Cars") / 2), "", "","","","","","","","",""
The Printer.scalewidt/2 and all there is finding the center of the page and setting the position of the text to start far enough left that the center of the text is in the center of the page 
Then you would just run through your SQL query and print off the results...
VB Code:
For each result in SQL_Query 'Sorry never worked with SQL so not sure how youd run through the results
PrintLine Car, 1, Make, 5, Model, 10, Reg_Num, 15,"","","",""
Next
And finally tell the printer your finished so it actually prints
Now you can obviously better this code in many ways, like I said this is one of my old functions but the first one that I came accross that would work for you. For one you could set anything past the first column as optional in the printline sub so that you dont have to have all the extra "","".
And the positions of the columns I gave you might need to be adjusted, and the would not account for text being to long or anything like that so you might have overrun of text. But I think this is something simple enough to get you started on your path to printing 
Hope it helps
-
Oct 19th, 2003, 04:17 PM
#6
Thread Starter
Frenzied Member
hey ya.
i haven't got a printer installed on this machine, so i will need to wait till i get to college to test it.
it helps a quite a bit tho, TNX.
(BTW: im guessing .print = single like just like PRINT filenumber,text on files?)
and also:
do i need to manually change to new pages using the .NewPage, or does it automatically go to new pages?
and final question (for tonite at least) is there a way to preview how it will print, without using a third party object?
Thanks.
-
Oct 19th, 2003, 04:50 PM
#7
Thread Starter
Frenzied Member
-- ok, that was not quite the last question:
i have tested out my code on a form1.print thing etc.
i have worked out that: imma need the printout to be in landscape (lots of data in the columns etc) so, i know i do it via:
printer.Orientation (SP?)
but what is the constant for landscape?
-
Oct 19th, 2003, 05:29 PM
#8
Frenzied Member
VB Code:
Printer.Orientation = vbPRORLandscape
By the way, use the object browser. Comes in very handy 
Mega.
"If at first you don't succeed, then skydiving is not for you"
-
Oct 19th, 2003, 05:32 PM
#9
Thread Starter
Frenzied Member
i searched for landscape in the object browser -- didnt return that the first time -- just searched again, and its there now (weird eh)
-
Oct 20th, 2003, 05:46 PM
#10
Thread Starter
Frenzied Member
ok guys,
just wanted to say: it prints out fine now 
however: there are a cpl of questions i need answering if ne one is sure of them?
1) Print Preview - Without any third party controls - Possible?
2) .NewPage -- need to add these manually, or should the printer deal with this? -- I can check later i guess by printing off a couple of 1-100 lines of text or dat, but rather have the knowledge w/o wastin the paper 
Thanks guys.
-
Oct 20th, 2003, 06:14 PM
#11
1. Replace the Printer. with Picture1 (PictureBox control, except for .EndDoc [or something close to that], etc)
2. If the printer doesn't handle it (I'm not quite sure if it does or not), you can use the TextHeight method of the Printer Object to check if it is greater than the Printer.Height property (some conversions may be necessary)
The time you enjoy wasting is not wasted time.
Bertrand Russell
<- Remember to rate posts you find helpful.
-
Oct 20th, 2003, 06:15 PM
#12
ASCII character 12 will add a new page. Its actually a form feed.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Oct 22nd, 2003, 10:41 PM
#13
Fanatic Member
As for your actual question on if you have to add a new page or not. I believe you will. What I do most of the time is in the loop for printing stuff have do a check like this
VB Code:
If Printer.CurrentY > 23 then Printer.NewPage
Of course you can get a lot more complex and 23 is just a descent sized margine on a normal 8 1/2 x 11 paper with the scale mode in vbcentimeters (23 is actually measured down from the near top of the page.) If your in landscape that number is gonna need to be smaller.
Or like in some of my more complex print functions I have margins and all set up where I would actuall figure up based on the paper height and all where to stop for a margin.
Like I said it can get a lot more complex but for simplicity sake and you just starting a straight number (CM measured from top of whatever orientation your using) where you would want to start the next page would work.
If you dont do this I think it depends on your printer wether it has a default margin that it wont print past or not. I Know my old Dot matrix Panasonic KX would just keep printing even half of line on one page and half on the next.. but my HP Deskject 950c leaves about a cm and skips to the next page automatically.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|