BarCode ActiveX Methods
|
AboutBox Method
Opens an About window.
Syntax
object.AboutBox()
Return Value
No return value.
|
ShowProperties Method
Opens a custom properties of the Barcode ActiveX Control.
Syntax
object.ShowProperties()
Return Value
No return value.
|
SaveToImageFile Method
Saves the image of the barcode to a file.
Syntax
object.SaveToImageFile(cx, cy, sFileName, [lRes,] [dm])
Parameters
cx | A double that defines the barcode picture width. |
cy | A double that defines the barcode picture height. |
sFileName | A string expression defining the file name. |
lRes | Optional (default 0). A long value that sets the picture resolution. |
dm | Optional (default dmPixels). This value defines the units that should be used to specify cx and cy. See remarks. |
Return Value
No return value.
Remarks
The format the file will be saved in depends on the extension of the file name For example, if you specify sFileName as "img1.jpg", the barcode will be saved as JPEG.
The following extensions can be used - "wmf", "emf", "bmp", "jpg", "jpeg", "gif", "tiff" and "png".
The dm parameter may has the following values:
dmMils = 0, mils(0.001 inches)
dmInches = 1, inches
dmMM = 2, millimeters
dmPixels = 3, pixels
If the size of an image (cx, cy) is not specified in pixels, its actual size will be calculated using
the specified picture resolution - lRes.
Warning! For this method to function properly, you should have the GDI+ library (gdiplus.dll)
installed on your PC, this library is distributed with Windows XP and higher. if you do not have this library,
you can download it here, and copy it to the
folder "../Windows/System32/".
Examples
'1. 'Save the image to a file of the JPEG format. The size of the image will be 200x100 pixels with the resolution of 96 dpi.
Call ActiveBC1.SaveToImageFile(200, 100, "c:\barcode.jpg")
'2. 'Save the image to a file of the JPEG format. The size of the image will be 50x25 millimeters with the resolution of 300 dpi.
Call ActiveBC1.SaveToImageFile(50, 25, "c:\barcode.jpg", 300, dmMM)
'3. Calculate the required barcode width. See GetBarcodeWidth method.
Dim barWidth As Double
barWidth = ActiveBC1.GetBarcodeWidth(0.5, 300, 300, dmMM)
'Save the image to a file of the JPEG format. The barcode will have the x-dimension of 0.5 mm and the height of 25 mm.
Call ActiveBC1.SaveToImageFile(barWidth, 25, "c:\barcode.jpg", 300, dmMM)
|
PartialWritePicture Method
Saves the barcode to an existing image file. The barcode can occupy just the part of
the image file it needs.
Syntax
object.PartialWritePicture(sFileName, x, y, width, height)
Parameters
sFileName | A string expression defining the file name. |
x | An integer value that defines the X coordinate of the barcode. |
y | An integer value that defines the Y coordinate of the barcode. |
width | An integer that defines the barcode width. |
height | An integer that defines the barcode height. |
Return Value
No return value.
Remarks
The image file defined by the sFileName parameter can be of the following formats: "bmp",
"jpg", "jpeg", "gif", "tiff" and "png".
Examples
Call ActiveBC1.PartialWritePicture("c:\1.jpg", 10, 10, 115, 50)
You can use this method to add a barcode to any of your image files. This barcode
can be used to identify the file or serve other purposes.
|
DrawBarcodeToSize Method
Draws the barcode in the device context. You can use either printer or screen as the device context.
Syntax
object.DrawBarcodeToSize(X, Y, CX, CY, dm, [hDC])
Parameters
X | A double value that defines the X coordinate of the barcode. |
Y | A double value that defines the Y coordinate of the barcode. |
CX | A double that defines the barcode width. |
CY | A double that defines the barcode height. |
dm | Optional (default dmPixels). This value defines the units that should be used to specify cx and cy. See here. |
hDC | Optional (default 0). The handle of the device context where the barcode will be drawn.
If this parameter is not specified or set to zero, the printer device context will be used. |
Return Value
No return value.
Examples
'Draw a barcode to a screen.
Dim minWidth As Long
minWidth = oABarCode.MinBarcodeWidth
Call oABarCode.DrawBarcodeToSize(5, 5, minWidth, 45, dmPixels, Form1.hdc)
'Print a barcode 'Open a current printer
Call oABarCode.BeginPrint("")
'print a barcode to X=10 mm, Y=10 mm, WIDTH=100 mm, HEIGHT=25 mm
Call oABarCode.DrawBarcodeToSize(10, 10, 100, 25, dmMM)
Call oABarCode.EndPrint
See also
Barcode Programming FAQ
|
CopyToClipboard Method
Copies the image of the barcode onto the clipboard. After that you can insert this image into your
program using Ctrl+V or the Paste menu item.
Syntax
object.CopyToClipboard(cx, cy)
Parameters
cx | An integer value that defines the barcode picture width |
cy | An integer value that defines the barcode picture height |
Return Value
No return value.
|
BeginPrint Method
Opens access to a printer.
Syntax
object.BeginPrint(sPrinterName)
Parameters
sPrinterName | A string value that defines the name of the printer. The name of the printer can be determined in the Printer folder of the Control Panel.
If the name is blank, the default printer will be opened. |
Return Value
No return value.
Remarks
This function must be called first before other printing features are used.
Example
'Open a current printer
Call oABarCode.BeginPrint("")
'print a barcode to X=10 mm, Y=10 mm, WIDTH=100 mm, HEIGHT=25 mm
Call oABarCode.DrawBarcodeToSize(10, 10, 100, 25, dmMM)
'Start a new page
Call oABarCode.NewPage
'print a barcode to X=10 mm, Y=10 mm, WIDTH=100 mm, HEIGHT=25 mm
Call oABarCode.DrawBarcodeToSize(10, 10, 100, 25, dmMM)
Call oABarCode.EndPrint
|
EndPrint Method
Closes the printer. You cannot use any printing features after that.
Syntax
object.EndPrint()
Return Value
No return value.
|
NewPage Method
The StartPage function prepares the printer driver to accept data.
Syntax
object.NewPage()
Return Value
No return value.
|
EndPage Method
The EndPage function notifies the device that the application has finished writing to a page. This function is typically used to direct the device driver to advance to a new page.
Syntax
object.EndPage()
Return Value
No return value.
|
GetPrinterHDC Method
The function returns the handle of the printer previously opened with the help of the BeginPrint function.
Syntax
object.GetPrinterHDC()
Return Value
HDC
|
SetPrinterHDC Method
Defines the handle of the printer that will be used for printing. If this function is called, you
do not have to call BeginPrint. In this case the entire process of closing/opening the printer, etc.
will be controlled outside the BarCode-ActiveX control.
Syntax
object.SetPrinterHDC(hDC)
Parameters
hDC | Value that specifies the printer handle. |
Return Value
No return value.
Example
Printer.CurrentX = 2048
Printer.Print "BarcodeControls.com, VB Example"
'BarCode-ActiveX will use the Visual Basic Printer object
Call ActiveBC1.SetPrinterHDC(Printer.hdc)
'print a barcode
Call ActiveBC1.DrawBarcodeToSize(10, 10, 100, 25, dmMM)
Printer.EndDoc
|
BinaryWritePicture Method
This method is similar to SaveToImageFile, but instead of saving the image to a file it represents it as a byte array.
Syntax
object.BinaryWritePicture(sFmt, CX, CY)
Parameters
sFmt | String that specifies the file name extension. The following extensions can be used - "wmf", "emf", "bmp", "jpg", "jpeg", "gif", "tiff" and "png". |
CX | An integer that defines the barcode width |
CY | An integer that defines the barcode height |
Return Value
Variant that specifies safe array of the bytes.
Remarks
This method can be useful for sending the image over the Internet. For example, it can be used by the IIS server.
Warning! For this feature to function properly, you should have the GDI+ library (gdiplus.dll) installed on your PC, this library is distributed with Windows XP and higher. if you do not have this library, you can download it here, and copy it to the folder "../Windows/System32/".
Example
There is a short example of the ASP page distributed together with BarCode-ActiveX.
<%
' abarcode.asp
' (c) 1999-2005 www.BarcodeControls.com
dim oBarcode
Set oBarcode = Server.CreateObject("ABarCode.ActiveBC.1")
oBarcode.BarText = "01234567"
oBarcode.BarType = 0
' we are sending a GIF image to the client
Response.ContentType = "image/gif"
Response.BinaryWrite oBarcode.BinaryWritePicture("gif", 200, 100)
SET Barcode=nothing
%>
Note
This method requires the Server License.
|
GetBarcodeWidth Method
This method returns the width that the barcode must have in order to get the necessary x-dimension.
Syntax
object.GetBarcodeWidth(lModule, xRes, yRes, dm)
Parameters
lModule | This double value that defines the necessary x-dimension. |
xRes | A long value that defines the resolution in dpi) along x axis. |
yRes | A long value that defines the resolution in dpi) along y axis. |
dm | Optional (default dmPixels). This value defines the units that should be used to specify lModule. The result will be also returned in these units. See here. |
Return Value
The method returns the required barcode width in units determined by the dm parameter.
Example
'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)
Dim barWidth As Double
barWidth = oABarCode.GetBarcodeWidth(0.508, dpiX, dpiY, dmMM)
See also
Barcode Programming FAQ
|
|