Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


code 39 Barcode not printing out of vb.net correctly????

Posted on 2004-09-27
Medium Priority
Last Modified: 2011-10-03
We have returns employees who scan in specific barcodes and need other barcodes printed back out to them.  I am programming the export of the new barcodes that they will place on the return boxes.  I am having however problems formatting the barcode to sit well on a 2.25X2.5 label.  We are using a Zebra LP 2844 printer for the printing of the labels.  I haven't messed around much with printer objects in vb.net so I am fairly new to the whole thing.  Are there settings in my code that I should change to make the barcode fit??  Here is a sample barcode number: 6103766213SUNDT004425103.  I need that number to print out in the form of a barcode on the 2.25X2.5 label, but I am having all types of problems with the formatting.  Can someone please help me.  You guys are the best.  Here is my code:

Imports System.Drawing.Printing
Imports System.Drawing.Text

Public Class Form1
    Inherits System.Windows.Forms.Form
    Public ptrFont As Font
    Public strBarcode As String
    Public newBarcode As String

#Region " Windows Form Designer generated code "

    Public Sub New()

        'This call is required by the Windows Form Designer.

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
            End If
        End If
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents txtBarcode As System.Windows.Forms.TextBox
    Friend WithEvents lblPrevious As System.Windows.Forms.Label
    Friend WithEvents txtPrevious As System.Windows.Forms.TextBox
    Friend WithEvents btnExit As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.txtBarcode = New System.Windows.Forms.TextBox
        Me.lblPrevious = New System.Windows.Forms.Label
        Me.txtPrevious = New System.Windows.Forms.TextBox
        Me.btnExit = New System.Windows.Forms.Button
        Me.txtBarcode.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper
        Me.txtBarcode.Font = New System.Drawing.Font("Verdana", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.txtBarcode.ForeColor = System.Drawing.Color.FromArgb(CType(255, Byte), CType(128, Byte), CType(0, Byte))
        Me.txtBarcode.Location = New System.Drawing.Point(96, 32)
        Me.txtBarcode.MaxLength = 100
        Me.txtBarcode.Name = "txtBarcode"
        Me.txtBarcode.Size = New System.Drawing.Size(400, 27)
        Me.txtBarcode.TabIndex = 0
        Me.txtBarcode.Text = ""
        Me.lblPrevious.Font = New System.Drawing.Font("Rockwell", 12.0!, CType((System.Drawing.FontStyle.Bold Or System.Drawing.FontStyle.Italic), System.Drawing.FontStyle), System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblPrevious.ForeColor = System.Drawing.Color.Red
        Me.lblPrevious.Location = New System.Drawing.Point(56, 152)
        Me.lblPrevious.Name = "lblPrevious"
        Me.lblPrevious.Size = New System.Drawing.Size(160, 32)
        Me.lblPrevious.TabIndex = 1
        Me.lblPrevious.Text = "Previous Serial #:"
        Me.lblPrevious.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        Me.txtPrevious.Font = New System.Drawing.Font("Verdana", 9.75!, CType((System.Drawing.FontStyle.Bold Or System.Drawing.FontStyle.Italic), System.Drawing.FontStyle), System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.txtPrevious.ForeColor = System.Drawing.SystemColors.ControlText
        Me.txtPrevious.Location = New System.Drawing.Point(224, 160)
        Me.txtPrevious.MaxLength = 100
        Me.txtPrevious.Name = "txtPrevious"
        Me.txtPrevious.ReadOnly = True
        Me.txtPrevious.Size = New System.Drawing.Size(272, 23)
        Me.txtPrevious.TabIndex = 2
        Me.txtPrevious.Text = ""
        Me.btnExit.Location = New System.Drawing.Point(512, 208)
        Me.btnExit.Name = "btnExit"
        Me.btnExit.TabIndex = 3
        Me.btnExit.Text = "Exit"
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.BackColor = System.Drawing.Color.FromArgb(CType(192, Byte), CType(192, Byte), CType(255, Byte))
        Me.ClientSize = New System.Drawing.Size(600, 238)
        Me.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Name = "Form1"
        Me.Text = "Newgistics Barcode Application"

    End Sub

#End Region

    Private Sub txtBarcode_KeyDown(ByVal sender As Object, ByVal keyPress As System.Windows.Forms.KeyEventArgs) Handles txtBarcode.KeyDown
        If keyPress.KeyValue = Keys.Enter Then
            Dim ptrLabel As New PrintDocument

            strBarcode = txtBarcode.Text

            txtPrevious.Text = strBarcode
            ptrFont = New Font("IDAutomationHC39M", 12)
            newBarcode = "*" & strBarcode & "*"

            AddHandler ptrLabel.PrintPage, AddressOf Me.ptrLabel_PrintPage

        End If
    End Sub

    Private Sub ptrLabel_PrintPage(ByVal sender As Object, ByVal ptr As PrintPageEventArgs)
        Dim linesPerPage As Single = 0
        Dim yPos As Single = 0
        Dim leftMargin As Single = ptr.MarginBounds.Left
        Dim topMargin As Single = ptr.MarginBounds.Top
        Dim line As String = Nothing

        linesPerPage = ptr.MarginBounds.Height / ptrFont.GetHeight(ptr.Graphics)

        yPos = 100

        line = newBarcode

        ptr.Graphics.DrawString(line, ptrFont, Brushes.Black, leftMargin, yPos, New StringFormat)

    End Sub

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
    End Sub
End Class
Question by:icarus2256
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 22

Expert Comment

ID: 12165690
Have you not tried it using the printer's own code sequences for bar code printing?

Get the EPL2 manual here:

Look at the B command:

Syntax Bp1,p2,p3,p4,p5,p6,p7,p8,“DATA”
p1 = Horizontal start position (X) in dots
p2 = Ver ti cal start po si tion (Y) in dots
p3 = Rotation
   0 No rotation
   1 90 degrees
   2 180 degrees
   3 270 degrees
p4 = Bar Code selection (see Table 2-1)
p5 = Narrowbar width in dots. (see Ta ble 2-1).
p6 = Wide bar width in dots.
p7 = Bar code height in dots.
p8 = Print human readable code.
   B=yes or N=no.

Author Comment

ID: 12170525
I am a little confused with the printers own code sequence you suggested using.  Is this something that I must code in vb.net or something like textpad and send it to the printer??  Can't I configure print properties inside .net??  If not just help me through the printers code sequence you listed above.  Thanks
LVL 22

Accepted Solution

cookre earned 750 total points
ID: 12171155
I don't have one of those printers to test on, I'm just reading the above linked to manual, but it would appear that, as long as the printer is in AutoSense mode, you can sen EPL2 commands directly to the printer.  For example, sending the string:


will display the Code 39 barcode for 123456-789 according to the parameters:

p1=2 - horizontal dot position 2
p2=3 - vertical dot position 3
p3=1 - rotate 90 degrees
p4=3 - use Code 39
p5=4 - narrow bar width 4
p6=7 - wide bar width 7
p7=50 - bar height 50
p8=B - display human readable code

You'll have to fiddle with the various parameters to get it to fit on the stock you're using.

Also, take a look at:

Featured Post

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

A short article about problems I had with the new location API and permissions in Marshmallow
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.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

610 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