Results 1 to 2 of 2

Thread: Printing to LPT1

  1. #1

    Thread Starter
    Addicted Member parminder's Avatar
    Join Date
    Apr 2003
    Location
    India
    Posts
    168

    Printing to LPT1

    Hi to all VBians

    Here is the problem to print the some text on "LPT1"

    In VB6 following code works, and print text to printer attached on LPT1
    -----------------------------------------------------------------
    Dim fh As Integer
    fh = FreeFile
    TargetPrinter = Trim(Me.Text1.Text)
    Open TargetPrinter For Output As #fh
    Print #fh, "TEST PRINT"
    Print #fh, "=========="
    Print #fh, "aaaaaaaaaaaaaaa"
    Print #fh,
    Print #fh, "bbbbbbbbbbbbbbb"
    Print #fh, "ccccccccccccccc"
    Close fh
    --------------------------------------------------------------------
    Now I did same thing in VB.net as:

    In starting of code file :
    -----------------------------------------
    Imports System.IO
    -----------------------------------------
    and on an event of a button

    ---------------------------------------------------------------------------------
    Dim SW As StreamWriter
    Dim FS As FileStream
    FS = New FileStream("LPT1:", FileMode.Open)
    SW = New StreamWriter(FS)
    SW.WriteLine("Parminder")
    SW.Close()
    FS.Close()
    ----------------------------------------------------------------------------------
    This give me the following error:
    ==========================================================
    An unhandled exception of type 'System.NotSupportedException' in mscorlib.dll

    Additional information: File Stream was asked to open a device
    that was not a file. FileStream's constructors that take a string
    will only work with devices like "com1:" or "lpt1:", then call
    CreateFile yourself then use the FileStream constructors that
    take an OS handle as an IntPtr.
    ==========================================================


    NOW MY problem is that I am unable to CreateFile method.
    Where is this method.

    Thanks

  2. #2

    Thread Starter
    Addicted Member parminder's Avatar
    Join Date
    Apr 2003
    Location
    India
    Posts
    168

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