Menu

Linear Barcode ActiveX Programming

Programming FAQ

How to create an invisible Barcode ActiveX in Visual Basic?

How to print a barcode from Visual Basic?



How to create an invisible Barcode ActiveX in Visual Basic

For the Barcode ActiveX control to be used, there is no need to place it on a form as shown here. You can create an invisible barcode control from any application including your DLL.
The first thing needed in order to do it is to create an object using the CreateObject function (as shown below). After the object is created, you can use it as you want.
'Create a new instance of BarCode-ActiveX
Dim oABarCode As Object
Set oABarCode = CreateObject("ABarCode.ActiveBC.1")

'set BarCode-ActiveX properties
oABarCode.BarText = "Hello world"
oABarCode.BarType = Code128
oABarCode.ShowCheck = False

'using BarCode-ActiveX
Dim minWidth As Long
minWidth = oABarCode.MinBarcodeWidth
Call oABarCode.DrawBarcodeToSize(5, 5, minWidth, 45, dmPixels, Form1.hdc)

'destroy BarCode-ActiveX object
Set oABarCode = Nothing



How to print a barcode from Visual Basic

There are a few different ways to print a barcode from Visual Basic using our ActiveX Control.
  1. Using a Visual Basic Printer object.

    Printer.CurrentX = 2048
    Printer.Print "BarcodeTools.com, VB Example"


    'BarCode-ActiveX will use the Visual Basic Printer object
    Call ActiveBC1.SetPrinterHDC(Printer.hdc)

    'print two barcodes
    Call ActiveBC1.DrawBarcodeToSize(10, 10, 50, 25, dmMM)
    Call ActiveBC1.DrawBarcodeToSize(70, 10, 50, 25, dmMM)

    Printer.EndDoc


    printing a barcode from Visual Basic


  2. Using BarCode-ActiveX methods.

    'open a current printer
    Call ActiveBC1.BeginPrint("")

    'print two barcodes
    Call ActiveBC1.DrawBarcodeToSize(10, 10, 50, 25, dmMM)
    Call ActiveBC1.DrawBarcodeToSize(70, 10, 50, 25, dmMM)

    Call ActiveBC1.EndPrint



  3. How to print a barcode with a certain x-dimension..

    To find out what x-dimension is, click here.
    To print a barcode with a certain x-dimension, you should correctly specify the barcode width. You can calculate it using the GetBarcodeWidth function.

    Private Declare Function GetDeviceCaps Lib "gdi32" _
    (ByVal hdc As Long, ByVal nIndex As Long) As Long
          
    Private Const LOGPIXELSX = 88
    Private Const LOGPIXELSY = 90
    Private Sub PrintBarcode()
    					'Create a new instance of BarCode-ActiveX
        Dim oABarCode As Object
        Set oABarCode = CreateObject("ABarCode.ActiveBC.1")
    					'set BarCode-ActiveX properties
        oABarCode.BarText = "Hello world"
        oABarCode.BarType = Code128
        oABarCode.ShowCheck = False
        Dim barFont As New StdFont
        barFont.Name = "Courier"
        barFont.Size = 36
        barFont.Bold = True
        oABarCode.font = barFont
    					'open a current printer
        Call oABarCode.BeginPrint("")
        
    					'gets the printer resolution (dpi - dots per inch)
        Dim dpiX As Long, dpiY As Long
        dpiX = GetDeviceCaps(Printer.hdc, LOGPIXELSX)
        dpiY = GetDeviceCaps(Printer.hdc, LOGPIXELSY)
    					'calculate the required barcode width (in mm) for the
        'x-dimension of 0.508 mm (20 Mils)
        Dim barWidth As Double
        barWidth = oABarCode.GetBarcodeWidth(0.508, dpiX, dpiY, dmMM)
    					'print a barcode
        Call oABarCode.DrawBarcodeToSize(10, 10, barWidth, 25, dmMM)
        Call oABarCode.EndPrint
        Set oABarCode = Nothing
    End Sub