Results 1 to 2 of 2

Thread: Printing to a file

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2000
    Location
    U.K.
    Posts
    3

    Post

    I am trying to print directly to a file.

    When bringing up the common dialog I get an option to print to a file which when selected gives me a input box for printing.

    How can this be achieved programmatically though VB ?

    Thanks.

    ------------------

  2. #2
    Member
    Join Date
    Jan 2000
    Location
    Southbridge, MA, USA
    Posts
    40

    Post

    The following example uses a function, WriteOutput [if you need to have lots of paragraphs, each getting data separately, this will be whatever you construct to concatenate the text]; you supply the path and filename.ext. If you put code like this in a cmdButton_Click event, in no time at all, the file will be written. You don't have to use a RichTextBox, but if you have A LOT of text, you'll need to. You don't even have to use any TextBoxes, but they let you see, quickly, what you're doing. The keys to printing to a file are the Open, Print, and Close statements. --Carl

    Private Sub cmdPrintFile_Click()
    rtfOutputText.Text = WriteOutput(inputData)
    ' Export the text to the .txt file
    Dim intFileNumber As Integer
    intFileNumber = FreeFile
    Dim strFilePath As String
    strFilePath = "c:\path\" & "FileName.txt"
    Open strFilePath For Output As #intFileNumber
    Print #intFileNumber, rtfOutputText.Text
    Close #intFileNumber
    End Sub


    [This message has been edited by cfmoxey (edited 01-25-2000).]

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