Friday, 1 October 2021

How to Generate Barcode in VB.Net

In this post I will show you how to generate a barcode in VB.Net. A barcode or bar code is a way of representing data visually in a machine readable form which was invented by Norman Joseph Woodland and Bernard Silver and patented in the US in 1951. Barcodes represent data visually by varying the width and spacing of parallel lines which can be scanned by special optical scanners which are called barcode readers. Barcodes became commercially successful when used to automate supermarket checkout systems, a task for which barcodes have become almost universal. 

To create a project of Generating barcodes in VB.net, first of all you have to design an interface of the form with a picture box, two labels, two text boxes and two button as shown in the image.

Now, change the properties of the picture box as picbarcode, txtboxes as txtencode and txtdecode and btnEncode and btnDecode respectively. Finally add a reference of ZXing ("zebra crossing") an open-source, multi-format 1D/2D barcode image processing library.


If you want to learn about CRUD operations in VB.Net and Stored Procedures then click CRUD in VB.Net using Stored Procedures and if you want to learn about SQL  injection attack in VB.Net and SQL Server just simply click SQL Injection attack in VB.Net and SQL Server.

Now type the VB.Net code on different buttons of the form as under:


Imports ZXing

Public Class Form1
    Private Sub btnEncode_Click(sender As Object, e As EventArgs) Handles btnEncode.Click
        Dim barwriter As New BarcodeWriter
        barwriter.Format = BarcodeFormat.CODE_128
        picBarcode.Image = barwriter.Write(txtEncode.Text)
    End Sub
    Private Sub btnDecode_Click(sender As Object, e As EventArgs) Handles btnDecode.Click
        Dim barreader As New BarcodeReader
        Dim res = barreader.Decode(CType(picBarcode.Image, Bitmap))
        If res IsNot Nothing Then
            txtDecode.Text = res.Text
        End If

    End Sub

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub
End Class

Finally press F5 and run the project.

VB.Net, VB6

1 comments:

prabakaran on 28 February 2024 at 07:32 said...

sir, need payment qr code generator for vb6.0

Post a Comment

 

© 2018 Mastering Web Development: HTML, Bootstrap, PHP, ASP.NET & VB.NET Essentials - Designed by Mukund | Privacy Policy | Sitemap

About Me | Contact Me | Write For Us