Hey , i am new to visual basic.NET , i want to recognize a barcode device in VB.NET , further have to generate some barcodes using VB.NET and recognize barcodes through barcode device. so anyone can help me... Thank you

Dani AI

Generated

A short practical guide that complements the replies from , , and .

Start by deciding two things: the symbology needed (simple 1D versus 2D like QR or PDF417) and how the scanner presents itself to Windows (keyboard HID, virtual COM/USB-CDC, or a vendor-specific interface). For simple linear codes a font or a small generator is fine; for 2D or standards-compliant output use a barcode library/SDK.

Generating barcodes (image-based example)

  • Use an image generator for reliable output (works across printers). Popular .NET-friendly libraries include ZXing.Net (2D + many 1D) and small 1D libraries for Code128/EAN. Example: ZXing.Net to create a QR in VB.NET:
' ZXing.Net example (VB.NET)
Imports ZXing
Imports ZXing.Common

Dim writer As New BarcodeWriter()
writer.Format = BarcodeFormat.QR_CODE
writer.Options = New EncodingOptions With {.Width = 300, .Height = 300}
Dim bmp As Bitmap = writer.Write("payload string or URL")
PictureBox1.Image = bmp

Reading / recognising scanners

  • If the device exposes a COM port, use System.IO.Ports.SerialPort and handle DataReceived (thread-safe UI updates via Invoke/BeginInvoke). Example:
' SerialPort example (VB.NET)
Dim WithEvents scannerPort As New IO.Ports.SerialPort("COM3", 9600)

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    If Not scannerPort.IsOpen Then scannerPort.Open()
End Sub

Private Sub scannerPort_DataReceived(sender As Object, e As IO.Ports.SerialDataReceivedEventArgs) Handles scannerPort.DataReceived
    Dim s = scannerPort.ReadExisting()
    Me.BeginInvoke(Sub() TextBox1.AppendText(s))
End Sub

When the scanner appears as a keyboard HID but it’s important to detect the device source (not just the text), either register for Raw Input (to identify VID/PID) or use a timing heuristic (scanners send keystrokes very fast). Timing heuristic example:

' Fast-keystroke detector
Private keyBuffer As New System.Text.StringBuilder()
Private lastMs As Integer = 0
Private thresholdMs As Integer = 40

Private Sub TextBox1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox1.KeyPress
    Dim now = Environment.TickCount
    If lastMs = 0 OrElse now - lastMs > thresholdMs Then keyBuffer.Clear()
    lastMs = now
    keyBuffer.Append(e.KeyChar)
    If e.KeyChar = Chr(13) Then
        Dim scanned = keyBuffer.ToString().Trim()
        keyBuffer.Clear()
        ' handle scanned
    End If
End Sub

Quick troubleshooting checklist

  • Confirm exact symbology and checksum rules (EAN/UPC, Code128, PDF417 differ).
  • For font-based printing, ensure the font is installed on the printing endpoint and the printer DPI matches layout.
  • Verify scanner settings (output mode, suffix/prefix, symbology enable/disable).
  • For 2D or compliance needs, prefer a tested library/SDK rather than hand-rolled encoding.

This expands on earlier suggestions and gives concrete, ready-to-run patterns for generation and capture in VB.NET while highlighting when a library or Raw Input approach is the safer choice.

Recommended Answers

All 4 Replies

To generate barcodes you can use free3of9 barcode font. Its completely free and I've used on several projects to create scanner readable barcodes.

We rarely need to recognise barcode devices in programming. They usually simulate keyboard entry and you accept their input as would with normal keyboard.
To generate barcodes as hericles said you need a font. A free 3of9 font will do the job, usually by starting and ending your string with stars ( * ).

PS: Depending on the application a 3of9 font might not do the trick for you. There might be standards you have to follow or all your devices are setup for a particular encoding and you need to follow that. Whatever the case it's just a font.
PS2: The font that you'll use needs to be installed in all computers displaying / printing the barcode or you'll get the text version of your stirng. You don't need anything for just reading the barcode.

So far everyone has been assuming you want 3 of 9 barcodes, which isn't necessarily a safe assumption. If 3 or 9 or another simple linear barcode symbology is acceptable then it can be as easy as adam_k suggested: barcode readers are usually USB and send translated results directly through standard input as if it were a keyboard. Printing barcodes is equally trivial given a font and minimal formatting efforts (ie. the asterisk wrapping for 3 of 9).

However, if you need to use stacked or 2D barcodes things get harder because there are encoding steps involved. For example, the PDF417 symbology uses a complex algorithm to produce the encoded result, which is then displayed by the font. Without the encoding, readers will fail to recognize the barcode. This is where it makes sense to use a library to do the heavy lifting.

For creating Bar Codes ( either 2D and also 3D bar codes ) I've used the bar code library from Tal Tech. Check them out at http://www.taltech.com They also offer bar code reader devices.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.