Quick to scan Code 128 barcodes in VB.NET WinForms, WPF application
Here we will show how to scan and recognize Code 128 (linear 1D barcode symbology) using the VB.NET Barcode Reader library.
You can implement Code 128 barcode scanning with a direct method call in VB.NET. The core scanning method accepts an image source and target barcode type as input parameters.
You can implement Code 128 barcode scanning with a direct method call in VB.NET. The core scanning method accepts an image source and target barcode type as input parameters.
- Call the core decoding method
BarcodeScanner.Scan(). - Pass the barcode image file path as the first parameter.
- Specify the barcode type as
BarcodeType.Code128. - The method returns a string array containing all decoded barcode data.
Dim datas As String() = BarcodeScanner.Scan( "code-128-barcode-image.gif", BarcodeType.Code128)
Scan Code 128 barcode image in memory
The BarcodeScanner.Scan() method supports not only image file paths but also Stream objects as input. This is ideal for in-memory image processing in desktop applications. You can load image bytes into a MemoryStream and perform scanning directly without physical files.
- Read the image file into a byte array.
- Convert the byte array to a
MemoryStreamobject. - Call
BarcodeScanner.Scan()with theStreamandBarcodeType.Code128. - Get the decoded barcode data as a string array.
' Read image file into a byte array Dim dataBytes As Byte() = File.ReadAllBytes("code128-barcode.png") ' Create a MemoryStream from the byte array Dim barcodeInStream As Stream = New MemoryStream(dataBytes) ' Scan Code 128 barcode from the Stream object Dim datas As String() = BarcodeScanner.Scan(barcodeInStream, BarcodeType.Code128)
Scan Code 128 from multi-barcode formats
If your image contains multiple barcodes with different symbologies, you can scan all of them in one operation.
The VB.NET Barcode Reader library supports combined barcode type detection. You can identify each barcode type using the returned metadata.
The VB.NET Barcode Reader library supports combined barcode type detection. You can identify each barcode type using the returned metadata.
- Call the
BarcodeScanner.ScanInDetails()method for detailed barcode information. - Combine multiple barcode types using the Or operator:
BarcodeType.Code128OrBarcodeType.Code39. - Validate the returned result array.
- Iterate through the
BarcodeDetailarray. - Use the
Typeproperty to distinguish between different barcode formats. - Call
GetMessage()to retrieve the decoded text for each valid barcode.
' Scan mixed barcodes: Code 128 and Code 39 in one operation Dim datasInDetail As BarcodeDetail() = BarcodeScanner.ScanInDetails( "sample-barcodes.png", BarcodeType.Code128 Or BarcodeType.Code39) ' Check if valid scanning results are returned If datasInDetail IsNot Nothing AndAlso datasInDetail.Length > 0 Then ' Iterate all detected barcode records For Each barcodeInfo As BarcodeDetail In datasInDetail ' Identify and process Code 128 barcode If barcodeInfo.Type = BarcodeType.Code128 Then Dim Code128Text As String = barcodeInfo.GetMessage() End If Next End If
How to retrieve scanned Code 128 barcode properties in VB.NET?
Here we will learn how to retrieve complete information from scanned Code 128 (linear 1D barcode symbology) using the VB.NET Barcode Reader library.
The VB.NET Barcode Reader library can extract comprehensive metadata from scanned Code 128 barcodes. All details are accessible through the barcode result object for desktop application processing.
The VB.NET Barcode Reader library can extract comprehensive metadata from scanned Code 128 barcodes. All details are accessible through the barcode result object for desktop application processing.
- Code 128 text message: The decoded raw data string from the barcode.
- Verified barcode format: The confirmed and validated symbology type.
- Code 128 position: The location and bounding coordinates of the barcode in the source image.
- Code 128 start & encoding code set: The encoding mode used to generate the barcode.
- Code 128 checksum codeword value: The validation check digit used for data integrity verification.
Extract Code 128 core information
You can access and validate key Code 128 barcode data through the returned
Below are the most commonly used members for barcode processing.
The VB.NET codes below show how to implement Code 128 scanning and data extraction in VB.NET application.
BarcodeDetail object.
Below are the most commonly used members for barcode processing.
Type
Validates that the detected barcode is Code 128.
This is critical when scanning images with multiple barcode formats.GetMessage()
Returns the raw decoded text string of the Code 128 barcode.GetASCIITextMessage()
Returns the processed ASCII text string of the Code 128 barcode.
All non-printable ASCII characters are replaced with defined label characters.
The VB.NET codes below show how to implement Code 128 scanning and data extraction in VB.NET application.
- Call
BarcodeScanner.ScanInDetails()to scan the barcode image. - Set the target barcode type to
BarcodeType.Code128. - Check if valid scanning results are returned.
- Iterate through the
BarcodeDetailarray. - Read and output the barcode type, raw text, and formatted ASCII text.
' Scan Code 128 barcode and retrieve detailed barcode information Dim result As BarcodeDetail() = BarcodeScanner.ScanInDetails( "Code128-sample-image.png", BarcodeType.Code128) ' Check if valid barcode results are detected If result IsNot Nothing AndAlso result.Length > 0 Then ' Iterate all scanned barcode records For Each barcodeInfo As BarcodeDetail In result Console.WriteLine("Barcode Format: {0}", barcodeInfo.Type) Console.WriteLine("Code 128 text: {0}", barcodeInfo.GetMessage()) Console.WriteLine("Code 128 ASCII text: {0}", barcodeInfo.GetASCIITextMessage()) Next End If
Code 128 position, rotation, check sum, and encoding mode
You can obtain the geometric information of the scanned Code 128 barcode directly from the
After obtaining the
Here are these steps to extract full Code 128 information in VB.NET:
BarcodeDetail object.
Rotation: Gets the rotation angle of the detected barcode.X1, Y1, X2, Y2, X3, Y3, X4, Y4: Gets the 4 vertex pixel coordinates that define the barcode bounding box in the image.
After obtaining the
BarcodeDetail object, you can call the GetBarcodeProps() method.This method returns a Code128Props (Code 128 dedicated property entity) object for advanced decoding information.
StartSet: Gets the initial encoding code set used by the Code 128 barcode (A, B, or C).IsMixSet: Returns True if multiple code sets are used in a single barcode.Checksum: Gets the checksum codeword value (valid range: 0 to 102) for data validation.
Here are these steps to extract full Code 128 information in VB.NET:
- Call
BarcodeScanner.ScanInDetails()to scan the barcode image. - Check for valid scanning results.
- Read basic information, rotation angle, and position coordinates.
- Cast the barcode properties to
Code128Propsfor advanced data. - Read and output start code set, mixed set status, and checksum value.
' Scan Code 128 barcode and retrieve detailed information Dim result As BarcodeDetail() = BarcodeScanner.ScanInDetails( "Code128-sample-image.png", BarcodeType.Code128) ' Check if valid barcode data is detected If result IsNot Nothing AndAlso result.Length > 0 Then ' Iterate all scanned barcode records For Each barcodeInfo As BarcodeDetail In result ' Output basic barcode text Console.WriteLine("Barcode Format: {0}", barcodeInfo.Type) Console.WriteLine("Code 128 text: {0}", barcodeInfo.GetMessage()) Console.WriteLine("Code 128 ASCII text: {0}", barcodeInfo.GetASCIITextMessage()) ' Output rotation and position coordinates Console.WriteLine("Rotation angle: {0}", barcodeInfo.Rotation) Console.WriteLine("Barcode Position X1: {0}, Y1: {1}", barcodeInfo.X1, barcodeInfo.Y1) Console.WriteLine("Barcode Position X2: {0}, Y2: {1}", barcodeInfo.X2, barcodeInfo.Y2) Console.WriteLine("Barcode Position X3: {0}, Y3: {1}", barcodeInfo.X3, barcodeInfo.Y3) Console.WriteLine("Barcode Position X4: {0}, Y4: {1}", barcodeInfo.X4, barcodeInfo.Y4) ' Extract advanced Code 128 properties If barcodeInfo.Type = BarcodeType.Code128 Then Dim props As Code128Props = CType(barcodeInfo.GetBarcodeProps(), Code128Props) ' Output advanced encoding properties Console.WriteLine("Start Set: {0}", props.StartSet.ToString()) Console.WriteLine("Is Mix Set: {0}", props.IsMixSet.ToString()) Console.WriteLine("Checksum: {0}", props.Checksum.ToString()) End If Next End If
How to read Code 128 ASCII text in VB.NET?
Code 128 supports encoding of all 128 standard ASCII characters.
A common example is the carriage return control character, represented as [CR]. Its ASCII value is 13. A sample barcode might contain encoded text such as
You can scan raw barcode data and manually replace control characters with readable labels using VB.NET Barcode Reader library.
The VB.NET Barcode Reader library provides the
- 95 characters are printable, including digits (0-9), uppercase letters (A-Z), lowercase letters (a-z), and special symbols.
- The other 33 characters are non-printable control characters.
A common example is the carriage return control character, represented as [CR]. Its ASCII value is 13. A sample barcode might contain encoded text such as
Code[CR]128.
You can scan raw barcode data and manually replace control characters with readable labels using VB.NET Barcode Reader library.
- Call
BarcodeScanner.Scan()to decode the Code 128 image. - Iterate through the returned text results.
- Replace the carriage return character
\rwith the label[CR]. - Output both raw and formatted text messages.
' Scan Code 128 barcode with control characters Dim result As String() = BarcodeScanner.Scan( "C:\Input\code128-none-printable-chars.png", BarcodeType.Code128) ' Process and display raw and formatted messages For Each msg As String In result Debug.WriteLine("Barcode Raw Message: '" & msg & "'") ' Replace carriage return control character with [CR] Dim tmp As String = msg.Replace(vbCr, "[CR]") Debug.WriteLine("Barcode Message: '" & tmp & "'") Next
The VB.NET Barcode Reader library provides the
GetASCIITextMessage() method. This method automatically replaces non-printable control characters with visible text labels.
- Create a
ScanOptionsobject for Code 128. - Scan the image using
BarcodeScanner.Scan(). - Call
GetASCIITextMessage()to get the formatted text directly. - Output the processed barcode text.
' Configure scanning options Dim opts As New ScanOptions(BarcodeType.Code128) ' Scan and retrieve detailed barcode information Dim datas As BarcodeDetail() = BarcodeScanner.Scan( "C:\Input\code128-none-printable-chars.png", opts) ' Get automatically formatted ASCII text For Each obj As BarcodeDetail In datas Debug.WriteLine("Barcode Text: " & obj.GetASCIITextMessage()) Next
Verify scanned Code 128 barcode data using check character in VB.NET
Code 128 uses one mandatory check character for validity verification.
The VB.NET Barcode Reader library provides built-in check character validation. It uses the scanned check character to verify data integrity automatically. Only valid barcode data will be returned to your application.
- This character is automatically calculated and appended during barcode generation.
- It is not displayed in the human-readable text label.
- It is not included in the final decoded output from barcode scanners or software.
The VB.NET Barcode Reader library provides built-in check character validation. It uses the scanned check character to verify data integrity automatically. Only valid barcode data will be returned to your application.
Note:
- Do not manually process or remove check characters in VB.NET code.
- Damaged, blurry, or modified barcodes will fail validation and return empty results.
- Automatic validation ensures data accuracy for industrial and desktop applications.
- This feature works for both image files and Stream object inputs.
Common Asked Questions
What is the barcode 128 text code?
Code 128 barcode is a high-density 1D barcode format, which encodes digits, text, control characters, and full ASCII 128 characters.
Using VB.NET Barcode Reader library, you will be able to scan, recognize barcode text from images file in VB.NET Windows Forms, WPF applications.
How do you read a Code 128 barcode?
Code 128 barcodes are including four parts:
- A start character
- Code 128 data characters
- A checksum digit
- A stop character
What scanners read Code 128?
Most commercial barcode scanner devices and free or paid barcode scanner software can read Code 128 barcodes from images or printed papers.
OnBarcode VB.NET Barcode Scanner library supports scanning and reading Code 128 barcodes in VB .NET app on Windows, macOS and Linux.
How do I scan a Code 128 barcode?
You can easily use a barcode scanner device, a phone or pad with camera, or barcode software or library to scan, decode Code 128 text from barcode images or printed papers.
VB.NET Barcode Reader library will enable your Visual Studio console and Windows apps to scan and recogize all Code 128 and other 2d, 1d barcodes from image files.
VB.NET Barcode Reader library will enable your Visual Studio console and Windows apps to scan and recogize all Code 128 and other 2d, 1d barcodes from image files.
How to read Code 128 checksum digit using barcode scanner software?
According to Code 128 ISO standard (ISO/IEC 15417), barcode scanner device or software will not return the Code 128 check sum character. OnBarcode VB.NET Barcode Reader library
will recognize and decode the Code 128 data text without the check digit in Visual Basic class.