Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version
Go to top

How to Generate Check Digits and verify your barcodes

, 28 Sep 2006
Generates Check Digits and alows you to verify proper scan of a barcode
barcodecheckdigandverify_demo.zip
BarcodeGenerator
BarcodeGenerator.vbproj.user
barcodecheckdigandverify_demozip.zip
BarcodeGenerator.suo
BarcodeGenerator.vbproj.user
Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        '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
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    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 Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents btnVerify As System.Windows.Forms.Button
    Friend WithEvents tbSysDig As System.Windows.Forms.TextBox
    Friend WithEvents tbProdCode As System.Windows.Forms.TextBox
    Friend WithEvents tbManfacID As System.Windows.Forms.TextBox
    Friend WithEvents btnGenerate As System.Windows.Forms.Button
    Friend WithEvents tbBarcode As System.Windows.Forms.TextBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.btnVerify = New System.Windows.Forms.Button
        Me.tbSysDig = New System.Windows.Forms.TextBox
        Me.tbProdCode = New System.Windows.Forms.TextBox
        Me.tbManfacID = New System.Windows.Forms.TextBox
        Me.Label1 = New System.Windows.Forms.Label
        Me.Label2 = New System.Windows.Forms.Label
        Me.Label3 = New System.Windows.Forms.Label
        Me.btnGenerate = New System.Windows.Forms.Button
        Me.tbBarcode = New System.Windows.Forms.TextBox
        Me.Label4 = New System.Windows.Forms.Label
        Me.SuspendLayout()
        '
        'btnVerify
        '
        Me.btnVerify.Location = New System.Drawing.Point(139, 120)
        Me.btnVerify.Name = "btnVerify"
        Me.btnVerify.TabIndex = 0
        Me.btnVerify.Text = "Verify"
        '
        'tbSysDig
        '
        Me.tbSysDig.Location = New System.Drawing.Point(32, 24)
        Me.tbSysDig.Name = "tbSysDig"
        Me.tbSysDig.TabIndex = 1
        Me.tbSysDig.Text = ""
        Me.tbSysDig.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
        '
        'tbProdCode
        '
        Me.tbProdCode.Location = New System.Drawing.Point(320, 24)
        Me.tbProdCode.Name = "tbProdCode"
        Me.tbProdCode.TabIndex = 2
        Me.tbProdCode.Text = ""
        Me.tbProdCode.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
        '
        'tbManfacID
        '
        Me.tbManfacID.Location = New System.Drawing.Point(176, 24)
        Me.tbManfacID.Name = "tbManfacID"
        Me.tbManfacID.TabIndex = 3
        Me.tbManfacID.Text = ""
        Me.tbManfacID.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(176, 8)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(100, 16)
        Me.Label1.TabIndex = 4
        Me.Label1.Text = "Manufacturer ID"
        Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(10, 8)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(144, 16)
        Me.Label2.TabIndex = 5
        Me.Label2.Text = "Number System Character"
        Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'Label3
        '
        Me.Label3.Location = New System.Drawing.Point(320, 8)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(100, 16)
        Me.Label3.TabIndex = 6
        Me.Label3.Text = "Product Code"
        Me.Label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'btnGenerate
        '
        Me.btnGenerate.Location = New System.Drawing.Point(219, 120)
        Me.btnGenerate.Name = "btnGenerate"
        Me.btnGenerate.TabIndex = 7
        Me.btnGenerate.Text = "Generate"
        '
        'tbBarcode
        '
        Me.tbBarcode.Location = New System.Drawing.Point(128, 80)
        Me.tbBarcode.Name = "tbBarcode"
        Me.tbBarcode.Size = New System.Drawing.Size(176, 20)
        Me.tbBarcode.TabIndex = 9
        Me.tbBarcode.Text = ""
        Me.tbBarcode.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
        '
        'Label4
        '
        Me.Label4.Location = New System.Drawing.Point(144, 64)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(144, 16)
        Me.Label4.TabIndex = 10
        Me.Label4.Text = "The Barcode"
        Me.Label4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(432, 150)
        Me.Controls.Add(Me.Label4)
        Me.Controls.Add(Me.tbBarcode)
        Me.Controls.Add(Me.btnGenerate)
        Me.Controls.Add(Me.Label3)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.tbManfacID)
        Me.Controls.Add(Me.tbProdCode)
        Me.Controls.Add(Me.tbSysDig)
        Me.Controls.Add(Me.btnVerify)
        Me.Name = "Form1"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub btnGenerate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGenerate.Click
        If Not tbSysDig.Text.Length = 1 Then
            MsgBox("Invalid System Digit")
        End If
        If Not tbManfacID.Text.Length = 5 Then
            If tbManfacID.Left < 5 Then
                tbManfacID.Text = tbManfacID.Text.PadLeft(5 - tbManfacID.Text.Length, "0")
            Else
                MsgBox("Invalid Manufacturer ID")
            End If
        End If
        If Not tbProdCode.Text.Length = 5 Then
            If tbManfacID.Left < 5 Then
                tbProdCode.Text = tbProdCode.Text.PadLeft(5 - tbProdCode.Text.Length, "0")
            Else
                MsgBox("Invalid Product Code")
            End If
        End If
        tbBarcode.Text = Barcode.GenerateCheckDigit(tbSysDig.Text & tbManfacID.Text & tbProdCode.Text)
    End Sub

    Private Sub btnVerify_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnVerify.Click
        If tbBarcode.Text.Length = 12 Then
            If Barcode.VerifyBarcodeInfo(tbBarcode.Text) Then
                MsgBox("Barcode is valid")
            Else
                MsgBox("Barcode is invalid")
            End If
        Else
            MsgBox("Invalid length")
        End If
    End Sub
End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Polymorpher
Software Developer (Senior) www.ruskin.com
United States United States
PC Programmer/Analyst

| Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 28 Sep 2006
Article Copyright 2006 by Polymorpher
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid