Search Tools Links Login

Print a Text File

Posted: 2019-10-02
By: AndreaTincani
Viewed: 254

Filed Under:

VB6 Files and I/O, VB6 Miscellaneous, VB6 Code Cache

No attachments for this post


Simple method to print a text file to the default printer.

Module

Option Explicit

Public Sub PrintTXTFile(FileName As String)
    Dim x As Integer
    Dim s As String

    x = FreeFile
    On Error GoTo HandleError
    Open FileName For Input As x
    Do While Not EOF(x)
        Line Input #x, s
        Printer.Print s
    Loop
    Printer.EndDoc
    Close #x
    Exit Sub
HandleError:
    MsgBox "Error :" & Err.Description, vbCritical, "Printing File..."
End Sub

Usage

Create a Form with a Command Button and a ListBox.

Private Sub Command1_Click()
    PrintTXTFile "C:\logon.reg"
End Sub

Special Instructions

This code originally appeared on AndreaVB.com, and has been republished here with the permission of Andrea Tincani.


Comments on this post

No comments have been added for this post.

You must be logged in to make a comment.