Results 1 to 14 of 14

Thread: [resolved]printing values from notepad to the printer

  1. #1

    Thread Starter
    Member
    Join Date
    May 2007
    Posts
    38

    [resolved]printing values from notepad to the printer

    hi i was wondering if someone can help me out. i wanted to print the values stored in the notepad file to the printer when i hit the command button. thx

    Private Sub cmdlabel_Click()
    Open "database.txt" For Output As #1
    Print #1, txtnamest
    Print #1, txtaddressst
    Print #1, txtaddressst1
    Print #1, txtcityst, txtstatest, txtzipcodest
    Print #1, txtcountryst
    Close #1
    End Sub
    Last edited by likewhoa; Apr 8th, 2008 at 07:00 PM.

  2. #2

    Thread Starter
    Member
    Join Date
    May 2007
    Posts
    38

    Re: printing values from notepad to the printer

    also for this line
    Print #1, txtcityst, txtstatest, txtzipcodest
    i was wondering if i can take out those spaces in between when it gets stored in notepad.

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: printing values from notepad to the printer

    try print #1, txtcityst & txtstatest & txtzipcodest
    but if you want to separate the txts you will have to do that your self like
    print #1, txtcityst & "," & txtstatest & "," & txtzipcodest
    change the comma if you prefer some other separator, or put a space

    to print the same to a printer
    vb Code:
    1. Print.print txtnamest
    2. Print.print txtaddressst
    3. Print.print txtaddressst1
    4. Print.print txtcityst, txtstatest, txtzipcodest
    5. Print.print txtcountryst
    6. printer.enddoc  ' finished so print and feed the paper out
    if you want to set the font or font size etc do that before the code above
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: printing values from notepad to the printer

    Quote Originally Posted by likewhoa
    i was wondering if i can take out those spaces in between when it gets stored in notepad.
    Wouldn't everything run together making it difficult to read?

  5. #5

    Thread Starter
    Member
    Join Date
    May 2007
    Posts
    38

    Re: printing values from notepad to the printer

    yess it worked thank you !!!

  6. #6

    Thread Starter
    Member
    Join Date
    May 2007
    Posts
    38

    Re: printing values from notepad to the printer

    actually those spaces were more like tabs in between so they were too far apart.

  7. #7

    Thread Starter
    Member
    Join Date
    May 2007
    Posts
    38

    Re: printing values from notepad to the printer

    hi i tested it but it does not print on the printer. but the spaces are ok now

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: printing values from notepad to the printer

    Quote Originally Posted by likewhoa
    hi i tested it but it does not print on the printer. but the spaces are ok now
    What does it do?

  9. #9
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: printing values from notepad to the printer

    My guess would be it doesnt print correct.

    This line with commas should be semi-colons will keep it on the same line.
    Print.print txtcityst, txtstatest, txtzipcodest

    Change to
    Print.print txtcityst; txtstatest; txtzipcodest

    Also, use ShellExecute API to print the text file just as if you did it manually from notepad.


    Code:
    Option Explicit
    
    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
                        ByVal hwnd As Long, _
                        ByVal lpOperation As String, _
                        ByVal lpFile As String, _
                        ByVal lpParameters As String, _
                        ByVal lpDirectory As String, _
                        ByVal nShowCmd As Long) As Long
    
    Private Const SW_HIDE As Long = 0
    Private Const SW_SHOWNORMAL As Long = 1
    Private Const SW_SHOWMAXIMIZED As Long = 3
    Private Const SW_SHOWMINIMIZED As Long = 2
    
    Private Sub Command1_Click()
        ShellExecute Me.hwnd, "print", "C:\Users\Public\Test1.txt", vbNullString, "C:\", SW_SHOWNORMAL
    End Sub
    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

  10. #10
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: printing values from notepad to the printer

    Change to
    Print.print txtcityst; txtstatest; txtzipcodest
    you missed my error
    all lines should be printer.print
    the comma will just print in the next print position, so should work fine, otherwise you can just print the identicle line you print to the file
    printer.print txtcityst & "," & txtstatest & "," & txtzipcodest
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  11. #11

    Thread Starter
    Member
    Join Date
    May 2007
    Posts
    38

    Re: printing values from notepad to the printer

    im getting a error when i use the printer.print on all the lines. for the shellexecute can i just type that or do i have to do something special.

  12. #12
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: printing values from notepad to the printer

    im getting a error when i use the printer.print on all the lines.
    what error? it should work fine
    are you working in vb6?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  13. #13

    Thread Starter
    Member
    Join Date
    May 2007
    Posts
    38

    Re: printing values from notepad to the printer

    ok now i got it to work it prints but im having trouble changing the font size can someone help me out thank you. this is what i have right now

    Printer.Print txtnamest
    Printer.Print txtaddressst
    Printer.Print txtaddressst1
    Printer.Print txtcityst & ","; txtstatest; " "; txtzipcodest
    Printer.Print txtcountryst
    Printer.EndDoc
    End Sub

  14. #14
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: [resolved]printing values from notepad to the printer

    printer.font.size = 14

    set the font, size, colour etc before printing the lines, you can change size between lines
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

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