Home arrow FAQs arrow Programming FAQ
Programming FAQ Print E-mail
I use you barcode control in ASP code. I would like to know if it is possible to save an image to the disk, for instance, as barcode.gif?

How to create an invisible Barcode ActiveX in Visual Basic?

How to print a barcode from Visual Basic?





I use you barcode control in ASP code. I would like to know if it is possible to save an image to the disk, for instance, as barcode.gif?

Sure, it is. You can use any properties and methods. Thus, you should use the SaveToImageFile method to save a barcode image.
<%
dim Barcode
Set Barcode = Server.CreateObject("ABarCode.ActiveBC.1")

Call Barcode.SaveToImageFile(250, 100, "c:\barcode.gif")

SET Barcode=nothing
%>
You should keep in mind that the user must have rights to write data to the corresponding folder. Usually, ASP code is executed under the IUSR_XXX account. And it usually has no such rights.


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
    


 

Copyright (c) 1999-2013, VBC Software. All rights reserved.
All trademarks mentioned are the property of their respective owners