Code Bar VB6 - How to Generate Barcode in Visual Basic 6 - ByteScout

Code Bar VB6 – How to Generate Barcode in Visual Basic 6

  • Home
  • /
  • Articles
  • /
  • Code Bar VB6 – How to Generate Barcode in Visual Basic 6

Code Bar VB6 tutorial shows how to generate barcodes in Visual Basic 6 using Barcode Generator SDK. Use the source code below for barcode generation.

  1. VB6 Code Sample
  2. Creating Barcode Generator Instance
  3. Configuring Barcode Symbology
  4. Providing Barcode Value and Saving Resulting Image

VB6 Code Sample

Set bc = CreateObject("Bytescout.BarCode.Barcode")
 
' display information about Code39 symbology
msgbox "Encoding '012345' using Code39 symbology" & vbCRLF &  bc.GetValueRestrictions(0) ' 0 = Code39 symbology
 
' set symbology to Code39
bc.Symbology = 1 ' 1 = Code39 symbology type
 
' set barcode value to encode
bc.Value = "012345"
 
msgbox "Saving Code39 barcode to 'Code39.png'"
 
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"

This is how easy to use ByteScout Barcode Generation SDK to generate barcodes with VBScript.

Thank you for reading!

Tutorials:

prev
next