FoxPro Barcode FAQ & Tutorial
In this FoxPro Barcode FAQ and tutorial, IDAutomation outlines integrating the Barcode ActiveX Control into Microsoft Visual FoxPro 6 forms and reports.
- Using the Barcode ActiveX Control
- Resolving version issues with the Barcode ActiveX Control
- Create Barcodes in FoxPro using Barcode Fonts
Integrating the ActiveX Control
- To use the ActiveX Control on a form, switch to '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.
- Assuming there is a data table already created, 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, such as in the VFP barcode example.
- Define code in the BeforeOpenTables event of the data environment
in the report: right-click on the report in the report designer
window, select "Data Environment" menu item, double click on
data environment window and write the code there, for example
in the picture below.
- The code might be a bit complex and require the use of a custom form. The code displayed in the 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 configuration. 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. Naturally, this will require recompiling of the VFP application.
The form code may also be modified 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 the 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 a 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.