?
Solved

printing a string variable in vb.net

Posted on 2006-05-29
13
Medium Priority
?
395 Views
Last Modified: 2012-05-05
Hello all,

Can anyone show me how to print a string variable to a network printer in vb.net windows form ?

Here is my code :

 Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
        Dim zPrint As String
        Dim zBlend As String
        Dim zBlend2 As String
        Dim zPart As String
        Dim zRack As String
        Dim zSlot As String

        zBlend = txtBlend.Text
        zBlend2 = txtBlend.Text
        zPart = txtPartNum.Text
        zRack = txtRack.Text
        zSlot = txtslot.Text

        zPrint = " ^XA^CFD^LH0,0^PR6^FS " & vbCrLf _
                 & " ^FWN^FS " & vbCrLf _
                 & " ^FX  " & vbCrLf _
                 & " ^FO25,30^A0N,60,70^FD" & zBlend & " ^FS " & vbCrLf _
                 & " ^FO35,85^A0N,30,20^FD" & zPart & "^FS " & vbCrLf _
                 & " ^FO25,115^BY2,2^BC,50,N,N,N^FD" & zBlend2 & "^FS " & vbCrLf _
                 & " ^FO25,170^A0N,30,20^FDRack:" & zRack & "  ^FS " & vbCrLf _
                 & " ^FO115,170^A0N,30,20^FDSlot:" & zSlot & " ^FS " & vbCrLf _
                 & " ^FO190,170^A0N,25,15^FD" & Date.Now.ToString & " ^FS " & vbCrLf & vbCrLf _
                 & " ^PQ<PRINTQTY>,0,1,Y^FS " & vbCrLf _
                 & " ^XZ "
        Dim printdoc As Printing.PrintDocument

    End Sub
0
Comment
Question by:abennett10
  • 5
  • 5
11 Comments
 

Author Comment

by:abennett10
ID: 16786535
How do I print the variable "zPrint" ?
0
 
LVL 5

Expert Comment

by:t_itanium
ID: 16787778
hi..

add to the project a printdocument control..

thens send the variable to the printdocument...
and call the print function of the printdocument to print document..

cheers
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:abennett10
ID: 16789139
Can you show me this in code ?
0
 
LVL 5

Expert Comment

by:t_itanium
ID: 16789481
you can do this by:

-add printdocument control to the form from the toolbox name it PrintDocument
-add a printdialog also from the toolbox name it PrintDialog
-in the event handler of print button .. write this..:


PrintDialog.Document = PrintDocument
If printDialog1.ShowDialog() = DialogResult.OK Then
Me.PrintDocument.Print()
End If

- then add to the event handler of PrintDocument PrintPage..so the event henadler  will look like this..:

Protected Sub PrintDocument_PrintPage(sender As Object, e As System.Drawing.Printing.PrintPageEventArgs)

   Dim left As Single = ev.MarginBounds.Left
   Dim Font As Font = TextBox1.Font
   Dim Brush As New SolidBrush(Color.Black)
   Dim y As Single = 0
   e.Graphics.DrawString(line, Font, Brush, left, y, New StringFormat())

End Sub
0
 

Author Comment

by:abennett10
ID: 16790231
Will this print to a network printer ?
0
 

Author Comment

by:abennett10
ID: 16790315
I received this error when I tried your code :

An unhandled exception of type 'System.ComponentModel.Win32Exception' occurred in system.drawing.dll

Additional information: The data area passed to a system call is
0
 
LVL 5

Expert Comment

by:t_itanium
ID: 16790931
it will print to the default printer..
just make the network printer ur default.....


try to type the exact error message to google you will find the solution in msdn microsoft

cheers
0
 

Author Comment

by:abennett10
ID: 16792130
Many different people will run this application.

If at all possible can you give me the code that will send my "zPrint" string variable to a IP specific printer ?

0
 
LVL 5

Accepted Solution

by:
t_itanium earned 1600 total points
ID: 16793052
try to specify the printer..

 PrintDocument.PrinterSettings.PrinterName = printername


or try if there is a property to define printer by IP..i think if there is no one.. you can use this previous line.

 PrintDocument.PrinterSettings . ......    = printerip
0
 
LVL 5

Expert Comment

by:t_itanium
ID: 16966450
?
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Progress

850 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