Solved

Line by Line printing in VB.NEt

Posted on 2010-09-22
9
1,204 Views
Last Modified: 2013-11-26
Hi
I have an application in VB6 that I am currently converting to VB.NET at work and we have a number of printers that work on a tractor feed due to the way we need to work.

Currently in the VB6 App when a part is processed the line printer will print a single line and wait for the next transaction, however we cannot get this to work the same in vb.net

The same code, simply will not work.  Does anyone have any ideas on how to sucessfully compelte this.

0
Comment
Question by:SimonPrice33
  • 5
  • 3
9 Comments
 
LVL 12

Expert Comment

by:jagssidurala
ID: 33735020
can you post your code please?
0
 

Author Comment

by:SimonPrice33
ID: 33735119
which, the .net or the vb6?
0
 

Author Comment

by:SimonPrice33
ID: 33735242
The top of the code section is the vb.net class that i have created in order to get it to complete a page print.

The code under the ----- is what calls the class

This allowd the pritner to complete a page print but its not what i need... I need a line print.


Public Class LinePrinter2
    Friend TextToBePrinted As String

    Public Sub Print(ByVal text As String)
        TextToBePrinted = text

        Dim prn As New Printing.PrintDocument

        Using (prn)
            'prn.PrinterSettings.PrinterName = "PrinterName"
            AddHandler prn.PrintPage, AddressOf Me.PrintPageHandler

            prn.Print()

            RemoveHandler prn.PrintPage, AddressOf Me.PrintPageHandler
        End Using
    End Sub

    Private Sub PrintPageHandler(ByVal sender As Object, _
       ByVal args As Printing.PrintPageEventArgs)

        Dim myFont As New Font("Microsoft San Serif", 10)

        args.Graphics.DrawString(TextToBePrinted, New Font(myFont, FontStyle.Regular), Brushes.Black, 50, 50)
    End Sub
End Class

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


            
PrintMsg = Prms.StationId & vbTab & DatePrn & vbTab & TimePrn & vbTab & Tran.Stub & vbTab & VB6.Format(Tran.Weight, "000") ' Print transaction


Dim lp As New LinePrinter2
            lp.Print(PrintMsg)

Open in new window

0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 7

Expert Comment

by:Alpha Au
ID: 33751465
I am guessing do you need to access the com1 and print to it?

http://support.microsoft.com/kb/823179
0
 

Author Comment

by:SimonPrice33
ID: 33767728
the printer is a networked printer so I'm not sure if this will work
0
 
LVL 7

Expert Comment

by:Alpha Au
ID: 33767788
let's try on some custom class

http://www.codeproject.com/KB/dotnet/LPrintWriter.aspx

LPrintWriter lprint = new LPrintWriter();
lprint.WriteLine("Hello, world!");
lprint.Close();
0
 

Author Comment

by:SimonPrice33
ID: 33767809
looking at the code, it looks similar to one that we called and spits out a full page.
I will try it shortly and let you know if there are any issues
0
 
LVL 7

Accepted Solution

by:
Alpha Au earned 500 total points
ID: 33767941
and you might need to refer to this if the custom class don't work

How to send raw data to a printer by using Visual Basic .NET
http://support.microsoft.com/?scid=kb;EN-US;322090
0
 

Author Closing Comment

by:SimonPrice33
ID: 33769636
I had seen a very similar solution in C#.NET but i find C# hard to read (which is why i code in VB.NET...

Solution worked as i required after a few modifications.

many thanks

0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question