Printing bar codes in 4D forms

This section assumes you have installed our bar code fonts and our bar code plug-in. See: Install bar code plug-in in 4D

Use bar code functions in all types of forms; Details Forms, List Forms, Details Forms for Printing, List Forms for Printing, etc. Because bar codes are not usually displayed, but are typically printed, you would likely use bar code functions in; Details Forms for Printing or List Forms for Printing.

Functions in the new bar code plug-in can be used in 4D, just like standard functions in 4th Dimension. There is a specific function to calculate each type of bar code, and a specific font (or a set of fonts) to print each type of bar code. In 4D, wherever you can select or enter command functions, you will now be able to view and select the command functions below the Barcode_CIAXCOM theme;



Design your form

To add bar codes to a form do the following.

- Select the Structure window. If it is not open, select the List of tables window and choose menu Use | Design

- If you want to add bar codes to an existing form, choose menu Design | Edit Form..., or to add bar codes to a new form choose menu Design | New Form...

Note: Alternatively, if the Structure window is select, open the Explorer (Ctrl+,) window. Choose the Forms tab, select a table and click Edit or New to edit or create forms.

Tricks with new forms

The first step of the New Form Wizard is to add fields that you want on your form. After you have added the fields you need, you could add additional fields (fields that you do not actually need on the form) and after the form has been created you will be able to modify these additional fields to print bar codes. If all fields in the table are already selected, you can add fields from unrelated tables by selecting All Tables instead of Master Table.

Note: Because the following bar code fonts display / print both the bar code and the human readable text, only one form field is needed to print the bar code and human readable text together; CIA UPC, CIA EAN, CIA Code 39 Normal Text, Codabar Normal Text or CIA POSTNET.

However, for most bar code types the human readable text (which you usually see printed below bar codes) is typically printed using a separate form field.

Convert an existing form field to a bar code

With your form open.

To change a field, from printing text, to printing a bar code - do the following;

- Select the field, right-click it and choose pop-up menu Object Properties... to display the Object Properties dialog, or the Property List dialog.

The object method can be as simple as;

AnBarcode := CIAXCOM_CODE128 ([Table 1]AnAlpha)

or, if you already have some code to trap other events, add this line to the On Display Details event and On Printing Details;

Case of
    : (Form event = On Display Detail )
        AnBarcode := CIAXCOM_CODE128 ( [Table 1]AnAlpha )
    : (Form event = On Printing Detail )
        AnBarcode := CIAXCOM_CODE128 ( [Table 1]AnAlpha )
End case

Adding a new form field to a form

A fast way of adding form fields to a form is to copy and paste existing form fields; which has the advantage of keeping the same style.

You can add fields using the Tools Palette (Ctrl-T).

- To display the Tools Palette right-click the form background and from the pop-up menu select Display | Tools Palette.

Select the variable field tool;

Click and drag on the form where you require the bar code. You can always change the size and position later.

Selecting the Variable field type

Select the variable field object that will print the bar code, then choose menu Form | Properties List or Object Properties.

Note: Alternatively right-click the field and choose pop-up menu Object Properties... then to switch between Property List or Object Properties right-click the form background and choose pop-up menu Display | Property List or Object Properties.

In the Property List box, change the Variable Type property to Variable

In the Object Properties box, select the Variable tab and change the Type property to Variable.

Displaying the Object Method dialog

To go directly to the Object Method dialog box, select the form field object that will print the bar code, then choose menu Object | Object Method... (alternatively, right-click the field and choose pop-up menu Object Method...).

If you prefer to use the Property List or Object Properties dialog boxes, then choose menu Form | Display | Properties List or Object Properties.

Note: Alternatively right-click the field and choose pop-up menu Object Properties... then to switch between Property List or Object Properties right-click the form background and choose pop-up menu Display | Property List or Object Properties.

To go to the Object Method from the Property List box, click the Edit button beside the Object Method property.

To go to the Object Method from the Object Properties box, select the Events tab and click the Object Method button.

Entering the Object Method


To make our variable field object display the contents of a field, this Object Method assigns the field to Variable1, like so;

Variable1 := [Table 1]AnInteger

Now our variable field object displays field [Table 1]AnInteger (i.e. a field called AnInteger in a table called Table 1).

To enter a field name quickly, you can double-click the field name in the Related Fields list (or Master Table list, or All Tables list).

If you wanted to display a field, so that it is formatted with leading zeros, you can use the String function. The Object Method would then be;

Variable1 := String ( [Table 1]AnInteger;"0000000" )

The String function a standard 4D function, listed under the String theme.

Selecting a bar code function

You can quickly enter the name of a bar code function by double-clicking it from the list below the Barcode_CIAXCOM theme. Theme Barcode_CIAXCOM is listed under the Commands by Themes list (or Commands by Alphabetical Order list).

Note: For each type of bar code, there is a specific function to use. For most applications Code 128 bar code are recommended, especially instead of Code 39. To produce Code 128 bar codes, simply use function CIA_CODE128( ) instead of CIA_CODE128( ).

See: Bar code functions.
See: Bar code font name and font size to use for more background information about each bar code type.
See: Advice for printing UCC-EAN-128 bar codes

The command themes of each plug-in is listed after all of the standard 4D command themes, so the Barcode_CIAXCOM theme is listed at the end, with other plug-in command themes.

This formula produces a Code 128 bar code of field AnInteger in table Table 1, by using function CIAXCOM_CODE128 with an argument of [Table 1]AnInteger

Variable1 := CIAXCOM_CODE128 ( [Table 1]AnInteger )

or better still, if we want all of the bar codes to contain zero padded values;

Variable1 := CIAXCOM_CODE128 ( String ( [Table 1]AnInteger;"0000000" ) )

When using complex formulas, test the result of each element of the formula. For example, before using the above formula, test the result of the String function is what you expected;

String ( [Table 1]AnInteger;"0000000" )

Some bar code functions (i.e. CIAXCOM_UPCA, CIAXCOM_EAN13, etc.) require a fixed number of numeric digits in the data string argument. This is because some bar code standards only supports a fixed number of digits. So, if you are creating this type of bar code, it is wise to check that all of the values you produce are all of the correct length.

Selecting the correct bar code font

There are several ways of selecting a font, but the best method is to select the form field that you want to print as a bar code, and then;

- Choose menu Font and select the font name

Then to set the font size;

- Choose menu Style | Other... and enter the exact point size



Copyright 2000 CIA (BAR CODES) UK. All rights reserved. Reproduction prohibited.