Results 1 to 13 of 13

Thread: [RESOLVED] print out a list of text...

  1. #1

    Thread Starter
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065

    Resolved [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
    Wayne

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  3. #3

    Thread Starter
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065
    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.
    Wayne

  4. #4
    Hyperactive Member deane034's Avatar
    Join Date
    May 2001
    Location
    Sri Lanka
    Posts
    485
    this may sound stupid.. but why not.. do the formatin using a rich text box.. and.. print it..
    me.life = VB

  5. #5
    Fanatic Member
    Join Date
    Sep 2002
    Location
    Lexington, SC
    Posts
    586
    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:
    1. Private Sub PrintLine(ColOne As String, ColOnePos As String,_
    2.  ColTwo As String, ColTwoPos As String, ColThree As String,_
    3. ColThreePos As String, ColFour As String, ColFourPos As String,_
    4. ColFive As String, ColFivePos As String, ColSix As String, ColSixPos As String)
    5.     If ColOnePos <> "" Then
    6.         Printer.CurrentX = ColOnePos
    7.         Printer.Print ColOne;
    8.         If ColTwoPos <> "" Then
    9.             Printer.CurrentX = ColTwoPos
    10.         End If
    11.         Printer.Print ColTwo;
    12.         If ColThreePos <> "" Then
    13.             Printer.CurrentX = ColThreePos
    14.         End If
    15.         Printer.Print ColThree;
    16.         If ColFourPos <> "" Then
    17.             Printer.CurrentX = ColFourPos
    18.         End If
    19.         Printer.Print ColFour;
    20.         If ColFivePos <> "" Then
    21.             Printer.CurrentX = ColFivePos
    22.         End If
    23.         Printer.Print ColFive;
    24.         If ColSixPos <> "" Then
    25.             Printer.CurrentX = ColSixPos
    26.         End If
    27.         Printer.Print ColSix;
    28.     End If
    29.     Printer.Print
    30. 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:
    1. Printer.ScaleMode = VbCentimeters 'The one I commonly use

    Then you would print your first line

    VB Code:
    1. 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:
    1. For each result in SQL_Query 'Sorry never worked with SQL so not sure how youd run through the results
    2. PrintLine Car, 1, Make, 5, Model, 10, Reg_Num, 15,"","","",""
    3. Next

    And finally tell the printer your finished so it actually prints

    VB Code:
    1. Printer.EndDoc

    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

  6. #6

    Thread Starter
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065
    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.
    Wayne

  7. #7

    Thread Starter
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065
    -- 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?
    Wayne

  8. #8
    Frenzied Member Mega_Man's Avatar
    Join Date
    Mar 2001
    Location
    North of England, South-East of Iceland
    Posts
    1,067
    VB Code:
    1. 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"

  9. #9

    Thread Starter
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065
    i searched for landscape in the object browser -- didnt return that the first time -- just searched again, and its there now (weird eh)
    Wayne

  10. #10

    Thread Starter
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065
    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.
    Wayne

  11. #11
    Only Slightly Obsessive jemidiah's Avatar
    Join Date
    Apr 2002
    Posts
    2,431
    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.

  12. #12
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  13. #13
    Fanatic Member
    Join Date
    Sep 2002
    Location
    Lexington, SC
    Posts
    586
    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:
    1. 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
  •  



Click Here to Expand Forum to Full Width