Results 1 to 4 of 4

Thread: Please help with this issue

Hybrid View

  1. #1

    Thread Starter
    PowerPoster Deepak Sakpal's Avatar
    Join Date
    Mar 2002
    Location
    Mumbai, India
    Posts
    2,424

    Question Please help with this issue

    Hi !

    VB Code:
    1. Open "LPT1:" For Output As #1
    2.     Print #1, "Hello!!"
    3. Close #1
    Above code prints data to LPT port. it works fine in vb6. Later on i upgraded that project to VB.Net which converted above code into following:
    VB Code:
    1. FileOpen(1, "LPT1:", OpenMode.Output)
    2.     PrintLine(1, "Hello")
    3. FileClose(1)
    Now this code is not working in VB.Net. It shows the following error, what that means

    error message:
    An unhandled exception of type 'System.NotSupportedException' occurred in microsoft.visualbasic.dll

    Additional information: FileStream was asked to open a device that was not a file. FileStream's constructors that take a String will only work with devices that are really files. If you need support for devices like "com1:" or "lpt1:", then call CreateFile yourself then use the FileStream constructors that take an OS handle as an IntPtr.



    Please help me with this issue

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    It means you can't open LPT1 as a stream/file anymore. Printing is kind of a pain in the ass now (until the next version of Visual Studio). Look up the help on the Printing.PrintDocument object which is how you print in .NET. Your sample would be something like this:
    VB Code:
    1. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    2.         Dim pd As New Printing.PrintDocument
    3.         AddHandler pd.PrintPage, AddressOf pd_PrintPage
    4.         pd.Print()
    5.     End Sub
    6.  
    7.     Private Sub pd_PrintPage(ByVal sender As Object, ByVal ev As Printing.PrintPageEventArgs)
    8.         ev.Graphics.DrawString("Hello", Me.Font, New SolidBrush(Color.Black), 10, 10)
    9.     End Sub

  3. #3

  4. #4
    Frenzied Member
    Join Date
    Jan 2001
    Posts
    1,374
    I am trying to output to a barcode printer. Has anyone had any success doing this? I have had no problem doing this in VB6 the way Deepak suggested.

    Edneeis's code outputs the string "Hello" to the default printer. I output OK to the laser printer but get an error message when I set the barcode printer as the default and try printing.

    "Tried to access printer with invalid settings"

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