Creating bar codes in 4D table triggers

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

Functions in the new bar code plug-in can be used in 4th Dimension, just like standard 4D functions. There is a specific function to calculate each type of bar code, and a specific font to print each type of bar code.

Concept

All bar code functions take one argument. The argument is a string of text characters that you want in the bar code (i.e. when the bar code is read, these characters are read back).

The bar code function uses this string argument to calculate a return string. The return string contains the characters that are actually required to print the bar code using our bar code fonts.

Usually this string is the contents of a field, or a field formatted as a string. Alternatively, the argument can be a expression that combines two or more fields as a string, or any kind of string expression involving; fields, constants, 4D functions, functions from other plug-ins, etc.

Note: All 4D field types (Alpha, Text, Real, Long Integer, Date, Integer, Time, Boolean, etc.) when they are formatted as a string - using 4D functions like String(exp; "format"), etc.

All of our bar code functions also return a string. When this returned string of characters is displayed or printed using a specific bar code font, you get the bar code symbol you want.

Step-by-step

In this section, we describe a method of creating bar codes from fields in a table and storing the string result in another field in the table. This method has several advantages. The main advantage is - when a table contains bar codes that are already calculated, the bar codes can be printed simply by printing the bar code field using a bar code font.

Note: In this documentation, when we use an Alpha field to store the string result of a bar code function, we refer to the field as a bar code field. But it is not really a bar code field, it is just an Alpha field that contains a text string that will print a bar code only when we print the field using a bar code font.

Another advantage - when a table contains bar codes that are already calculated, the 4D table can be accessed by external applications, and the bar codes can be printed simply by printing the bar code field using a bar code font.

Licensing: Users that only print bar codes must have licenses, because they are using our licensed bar code fonts.

To store the calculated string returned by the the bar code function you are going to use, you need to add an Alpha field to your table. This Alpha field  must be large enough to store the calculated string.

Add an Alpha type field to store bar code strings

In this example and the examples below we add an Alpha type field called AnBarcode.

To add a new field to a table do the following;

- In the List of tables window, select the table you want to all the bar code field to

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

- In the Structure window, right-click the table name, and from the pop-up menu choose New Field

 

- Enter a Field Name (we used AnBarcode in this example)

- Select Alpha as the field type and set the size of the field to 10 characters + 2 times the number of character you plan to print in your bar codes. For example, if your bar code will contain data from a field that contains up to 25 characters, then the new field should be 10 + (2 * 25) characters wide (i.e. 60 characters).

- If 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...

Adding a table trigger

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

- To view the Explorer, select the Structure window and choose menu Design | Edit Method

- To edit a table's trigger method, select the Methods tab and under Form Methods & Triggers select the table. Then click the Edit button.

Example trigger

The following example trigger is in an example form, based on an example table that has fields called AnBarcode and AnAlpha.

The trigger fills in the AnBarcode field with a Code 128 bar code using the data in field AnAlpha when any event happens.

Any time after this happens, the Code 128 bar code can be printed simply by printing the AnBarcode field using font CIA Code 128 Medium (or other CIA Code 128 fonts).

TIP: As a starting point you can paste this code and replace the field names with your own field names

Case of
    : (Database event = On Saving New Record Event)
        [Table 1]AnBarcode := CIAXCOM_CODE128 ( [Table 1]AnAlpha )
    : (Database event = On Saving Existing Record Event)
        [Table 1]AnBarcode := CIAXCOM_CODE128 ( [Table 1]AnAlpha )
End case

 

 

 


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