VB6 - Generate and Read BarCode - ByteScout
Announcement
Our ByteScout SDK products are sunsetting as we focus on expanding new solutions.
Learn More Open modal
Close modal
Announcement Important Update
ByteScout SDK Sunsetting Notice
Our ByteScout SDK products are sunsetting as we focus on our new & improved solutions. Thank you for being part of our journey, and we look forward to supporting you in this next chapter!

VB6 – Generate and Read BarCode

VB 6 generate and read barcode tutorial shows sample source codes for generating and reading barcodes with Visual Basic 6.

First of all, let’s see how to generate a barcode with ByteScout Barcode SDK with VBScript.

Generating Barcode

You can generate barcode with our BarCode Generator SDK in VB6 like this:

Set bc = CreateObject("Bytescout.BarCode.Barcode")
' set symbology to Code39
bc.Symbology = 1 ' 1 = Code39 symbology type
' set barcode value to encode
bc.Value = "012345"
bc.SaveImage "Code39.png"
Set bc = Nothing

The output of the above program is as below:

In order to use Bytescout barcode generation with VBScript, make sure you have “ActiveX” components installed. These components can be installed from the ByteScout SDK installation path. For example, in my machine, these SDKs are installed at “C:\Program Files\Bytescout BarCode Generator SDK“. In order to install ActiveX components, simply navigate to the “ActiveX” folder inside, and click on the “InstallAsActiveX.bat” file.

Now moving to code, though it is self-explanatory let’s review important snippets.

Creating barcode generator instance

Set bc = CreateObject("Bytescout.BarCode.Barcode")

We are creating a barcode generator instance and saving it in a variable named “bc“. We are using this code for demo purposes hence not passing any registration name and key, which will have a watermark in the generated output. In production, we should configure the registration name and key. We can do this by setting the properties “RegistrationName” and “RegistrationKey” like the following.

bc.RegistrationName = "demo"
bc.RegistrationKey = "demo"

Configuring Barcode Symbology

bc.Symbology = 1 ' 1 = Code39 symbology type

ByteScout Barcode SDK supports almost all types of barcode generation. Based on our requirement we can set the “Symbology” property with barcode type and generate barcode in that type.

Providing barcode value and saving resulting image

We can provide barcode value by setting the “Value” property.

bc.Value = "012345"

Barcode output can be obtained by setting the output file name to “SaveImage” method.

bc.SaveImage "Code39.png"

That’s all about generating a barcode. Now let’s review reading the barcode with ByteScout Barcode Reader.

Reading Barcode

And you can read barcode from an image in VB6 using BarCode Reader SDK:

Set bc = CreateObject("Bytescout.BarCodeReader.Reader")

' Set barcode type to find
bc.BarcodeTypesToFind.Code39 = True

bc.ReadFromFile "Code39.png"

For i = 0 To bc.FoundCount - 1
Msgbox "Found barcode on page #" & CStr(bc.GetFoundBarcodePage(i)) & " with type " & Cstr(bc.GetFoundBarcodeType(i)) & " and value " & bc.GetFoundBarcodeValue(i)
Next

Set bc = Nothing

The output of the above program is as below:

In order to use ByteScout Barcode Reader with VBScript, make sure you have “ActiveX” components installed. These components can be installed from the ByteScout SDK installation path. For example, in my machine, these SDKs are installed at “C:\Program Files\Bytescout BarCode Reader SDK“. In order to install ActiveX components, simply navigate to the “ActiveX” folder inside, and click on the “InstallAsActiveX.bat” file.

Now let’s review important parts of code.

Creating barcode reader instance

Set bc = CreateObject("Bytescout.BarCodeReader.Reader")

We are creating a barcode reader instance and saving it in a variable named “bc“. We are using this code for demo purposes hence not passing any registration name and key, which might have a watermark in the generated code output, also slower to process. In production, we should configure the registration name and key. We can do this by setting the properties “RegistrationName” and “RegistrationKey” like the following.

bc.RegistrationName = "demo"
bc.RegistrationKey = "demo"

Configuring Barcode type to read

' Set barcode type to find
bc.BarcodeTypesToFind.Code39 = True

ByteScout Barcode Reader SDK supports almost all types of barcodes. Based on our requirement we can set the “BarcodeTypesToFind” property with barcode type. If this property is not provided, it’ll automatically try to detect all possible barcode types and give output. In the cases when we already know the barcode type, it’s advised to always provide barcode type to have an improved reading operation. We can also further provide properties such as page no. to read from as well as a specific region on-page to read barcode from.

Providing input file and reading barcode values

We can use the method ReadFromFile to pass the input file to read the barcode.

bc.ReadFromFile "Code39.png"

ByteScout Barcode Reader SDK provides methods/properties to get result related fields. For example property “FoundCount” contains no barcodes found. Properties such as “GetFoundBarcodeType” and “GetFoundBarcodeValue” contains found barcode type and value respectively.

For i = 0 To bc.FoundCount - 1
Msgbox "Found barcode on page #" & CStr(bc.GetFoundBarcodePage(i)) & " with type " & Cstr(bc.GetFoundBarcodeType(i)) & " and value " & bc.GetFoundBarcodeValue(i)
Next

That’s how we can read barcode values using ByteScout Barcode Reader SDK.

Here is the demo of how to read barcode:

Thank you for reading!

Tutorials:

prev
next