How to print a text file in Visual Basic

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DGee
    New Member
    • Feb 2008
    • 5

    How to print a text file in Visual Basic

    Hi, this is my first post, so be nice on me!

    I currently have a program that will input and save into a text file. It stores information on the operations of the program, such as inputs, errors and major proccesses. I have literally torn the web into pieces looking for code to print the text document. I've tried opening it and printing or printing the file and i get the same result each time, that is that the text from the document extends across the entire printed page until it is cut off, in other words it doesn't go to the next line (despite multilined text box), and the printer doesn't set any margins.

    I have tried this in both .txt and .rtf and have the same issue.

    If anyone has any ideas or experiance in this are please post.

    Thanks a lot, have a good day.

    DGee
    Last edited by DGee; Feb 23 '08, 10:29 AM. Reason: Title, not explicit
  • jacobevans
    New Member
    • Aug 2007
    • 26

    #2
    I'd use FileSystemObjec t to print text to a text file.Heres an example.

    Code:
     On Error Resume Next
    Dim fso As New FileSystemObject, prefs As TextStream
        Set prefs = fso.CreateTextFile(App.path & "/settings.txt", True)
        With prefs
            .WriteLine txtServer.Text
            .WriteLine txtPort.Text
            .WriteLine chkResign.Value
            .WriteLine chkPrivacy.Value
        End With
    Be sure to reference the Microsoft Scripting Runtime under Projects > References.

    -Jacob
    Last edited by jacobevans; Feb 23 '08, 03:35 PM. Reason: Missing code tags.

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      If I read the original question correctly, the problem is not getting the text into a file, but getting it formatted on the printer.

      I'd say there are a number of options available, but would like to know in more detail what you're trying to accomplish. For instance, are you trying to get your program to send to the printer, or just writing text into a file that somebody will print out later? And what version of VB are you using?

      Comment

      • lorenzana
        New Member
        • Feb 2008
        • 3

        #4
        The best way to print in VB is located here:

        Last edited by Killer42; Feb 27 '08, 01:10 AM. Reason: Activate link

        Comment

        Working...