|
Home:
Products: FoxPro
Barcode FAQ & Tutorial: |
FoxPro Barcode FAQ & Tutorial
In this FoxPro Barcode FAQ and tutorial, IDAutomation presents a
few methods for using the Barcode ActiveX Control and Barcode Fonts in Microsoft
Visual FoxPro 6 forms and reports.
- Using self checking barcode fonts such as Code 39
- Using Barcode Fonts with the Program Module for barcode
fonts requiring check digits such as Code 128, Postnet, Interleaved 2 of 5 and
UPC
- Using the Barcode ActiveX Control
- Resolving version issues with the Barcode ActiveX Control
Method 1 - using
Self Checking Barcode Fonts,
MICR and
OCR fonts
Self-Checking Barcode
Fonts, MICR
and OCR fonts are compatible
with FoxPro and may be used with ease. To use a self-checking font such as
Code 39, an asterisk
"*" will need to be inserted before and after the bar code data encoded. Therefore,
when encoding TEST3OF9 in a barcode, the text will be displayed as *TEST3OF9*
in a label on form or in a field in report. The Code 39 font should be selected
for label on form or for field in report.
- In this example, a dynamic Code 39 barcode field will be added to a Visual
FoxPro 6.0 report with IDAutomation's
Code 39 barcode font.
The sample assumes that the data to be encoded in the barcode is stored in the
"Code" field of character type in the "Items" table.
- First, install one of IDAutomation's Code 39 barcode font packages by
downloading a
demo or
ordering a license.
- Open the report for editing. Select the "Field" button in the report controls
toolbar and click on the report layout where the bar code should be displayed.
This will open a dialog box for specifying the properties for new report field.
In this example, the Code field content is the one selected to include in the
barcode. Because the start and stop characters required for Code 39 need to
be added, the following expression in the dialog box for report field properties
needs to be entered.
- Resize the new field to the required size of the field. With the field selected,
choose Format - Font... in menu and choose one of the Code 39
Barcode Fonts. In this example, the IDAutomationHC39S font is used, which
is a "human readable" font provided in the
Code 39 Font Advantage Package.
In this example, Format - Align - Center Horizontally
and Center Vertically is chosen so the barcode will appear
in the middle of the field and then change the font size to 14 so it can be
easily scanned.
- Now, when the Items table is prepared and contains some data, preview of
the report should display a bar code in the Barcode column in the report.
- The process to display a barcode on the form using barcode fonts will require
some coding. To do this, put a TextBox control on the form, specify .T. for
ReadOnly property for it, then set the Font for displaying to the Barcode font
with size 14. Set the Alignment property to "2 - Center". After that, specify
the expression for displaying in the ControlSource property of the text box.
This is not possible in design time, so it needs to be assigned in run time.
Method 2 -
using IDAutomation's FoxPro Barcode Program Module or Source Code with
Barcode Fonts
LICENSE NOTICE: This source code may be incorporated in an application only
if a valid license from IDAutomation.com, Inc. is acquired for the associated font
and the copyright notices are not removed from the source code. Redistribution of
IDAutomation's fonts and components requires a Developer License.
- The program module and source code for FoxPro calculates the start, stop
and check digits for the barcode and returns a character string, that when combined
with the barcode font, creates a correct barcode.
- Download the
IDAutomation-prg.txt file and save it as IDAutomation.PRG.
- Add this file as a program module to the VFP project, set it as a procedure
file using SET PROCEDURE TO... ADDITIVE command somewhere in the main (startup)
code of the project and access the function in the application as necessary.
This is demonstrated in the following
Visual FoxPro Barcode Sample Project.
- Place the appropriate expression in the dialog box for report field properties.
For example, when using the Code 128 barcode font, call a code 128 function
defined in the program module. There is not really much difference in defining
properties in this method compared to Method 1,
except the expression is now a function defined in our program module.

Method 3 - using IDAutomation's
Barcode ActiveX Control
- To use it on form, in design time select the "ActiveX Control (OleControl)"
on the Form Control toolbar and click on the form. After the "Insert Object"
dialog box opens, select "Insert Control" option. In the list of all installed
ActiveX controls, select a control to use that begins with "IDautomation".
- The characteristics can then be modified in the properties window.
- To print barcodes on reports or labels, the Barcode ActiveX control should
be embedded and prepared in the table field of type General, and then displayed
in the report. This will require some programming of code for preparing the
Barcode ActiveX control in General field.
- Assume the same data table as in Method 1.
Add to the table the field of type General called "CodeGen".
- To display it in a report, put the Picture/ActiveX Bound Control, then select
the "File" option and specify General field and name in it ("Items.CodeGen").
- Then, prepare the code that will populate the General field by the Barcode
ActiveX control with appropriate data from the Code field for each record in
the Items table. This code should run before printing. This can be organized
by one of the following ways:
- Define code in the custom program that calls a report, like in the
VFP barcode
example.
- Define code in the BeforeOpenTables event of the data environment in
the report: right click on the report in report designer window, select
"Data Environment" menu item, double click on data environment window and
write the code there, like in the picture below.
- The code might be a bit complex and require use of a custom form. The code
displayed in above picture may be acquired
here or
download the
VFP barcode example for an implementation created in VFP 6.0,
which demonstrates how to store the BarCode ActiveX in the field of General
type, display it on a form and print. The sample also includes a simple code
to demonstrate how to prepare appearance and properties for the ActiveX control
embedded in General field before printing.
Resolving Version Issues with ActiveX
If a different version of the Barcode ActiveX Control is installed, errors may
appear in the existing Visual FoxPro application making use of the ActiveX Control.
One of the following suggestions below may resolve this issue:
If the form with the Barcode ActiveX on it does not open after installing
a new version of the ActiveX control:
The best way to fix this problem is to install a previous version of ActiveX
control again. Then open the VFP form and remember or write down all property settings
for BarCode ActiveX control (right-click on properties window and select the "Non-Default
Properties Only" option that will list all properties for which values should be
remembered). Remove the ActiveX control from the form and save the form. Close the
VFP development environment. Install the new version of the ActiveX control. Open
the form, put the ActiveX control on the form again and specify property values
in exactly the same way. Of course, this will require recompiling of the VFP application.
The form code may also be changed to enable the ActiveX control in code during
run time, as in the
VFP barcode example.
If the ActiveX control is created and property values assigned at run-time, different
versions of ActiveX on the form will work with the same code.
If
the Barcode ActiveX stored in fields of General type causes an error when trying
to use it:
After installing a different ActiveX control version, another program should
create a new ActiveX control in general field and set property values accordingly.
This will not require recompiling the application - only the data needs to be updated.
In the VFP barcode
example, there will be a sample of the report printed using a dynamically
prepared ActiveX control in General fields with sample of setting properties for
it. It is recommended to use this approach so a different version of the control
will not cause problems.
Special thanks to Vlad Grynchyshyn for providing information on using the
Barcode ActiveX Control in FoxPro.
© Copyright 2000-2008 IDAutomation.com, Inc., All Rights Reserved.
Legal Notices.
|
Over 70% of Fortune 100 companies
use IDAutomation's products to automate their businesses.
|