Barcodes in Visual Basic 6
Barcodes in Visual Basic 6
The easiest way to create barcodes in Visual Basic 5 or 6 is to use one of the Active Barcode
Components
To add an Active Barcode Component control to a Visual Basic form, select Components from the VB
Project menu. If axbarcode Active-X Control module is displayed in the list of available controls, then
ensure that it is checked. If it does not appear in the list user the Browse button to locate it in its
installation directory (or in Windows System or System32), then check its name in the list. Once
checked, an icon representing the component will appear in the toolbox.
Clicking on the Active Barcode Component icon in the toolbox causes the cursor to change to a cross.
Positioning the cross on a Visual Basic form, holding down the left mouse button and dragging the
cursor down and to the left, then releasing the mouse button, causes a rectangle to be drawn on the
form. An image of a (default) barcode will be shown within this rectangle. You may wish to use this
image of the component. Alternatively you may hide the component (by setting its Visible property to
false) and use the components methods and properties to create an image that is placed elsewhere on
the form - as in the sample Visual Basic program that is supplied with the component and uses code of
the form:
Axbarcode1.ImageHeight = i
Axbarcode1.ImageWidth = j
Axbarcode1.Xunit = 0
Axbarcode1.CodeType = type
Axbarcode1.Caption = Text
Image1.Picture = Axbarcode1.Picture
A single Visual Basic Form may contain any number of Active Barcode Components. The first to be
added will be called Axbarcode1, the second Axbarcode2, and so on; the names may be changed by
the user by modifying the Name property within the Visual Basic Properties box.
The Active Barcode Component may be operated entirely by setting or retrieving Property values using
the Basic language.
Clicking on the Active Barcode Component control on the form when VB's Properties box is displayed
will show the current settings for component's available properties. Most of these may be edited using
the Properties box, or may have their values set from within the user's program by statements of the
kind
Axbarcode1.Source="12345"
Active Barcode Component properties that are set AFTER a Picture is created may be retrieved within
user's programs by statements of the kind:
x=Axbarcode1.ErrorCode
Active Barcode Component produces its barcode image as a Windows metafile. This metafile is
displayed directly in the area you create for the component - unless you set the Axbarcode.Visible
property to FALSE.
To create a printable Picture object containing the barcode within a program the following steps may
be used:
1. Set those properties that Active Barcode Component requires to generate the barcode, the
minimum of which are
OR
If Axbarcode1.ErrorCode = 0 Then
Image1.Picture = Axbarcode1.Picture
To print the barcode image on the printer use the PaintPicture method of the Printer object, eg.
Barcode images may be saved in any of the supported graphics formats (BMP, EPS, GIF, PCX, PNG or
WMF) by using the SaveImage() method:
er = Abc1.SaveImage(fname$)
where fname is the full path name (including extension the identifies the graphic type) of the file that
will receive the image, and er is -1 if the file is created successfully, or 0 otherwise.