How to create CODE 39 and CODE 39 Extended barcodes

CODE 39 is the barcode developed by Intermec Corporation in 1975. Up to 43 characters including numbers, letters and some symbols can be included in the barcode: 0123456789 ABCDEFG HIJKLMNOP QRSTUVWXYZ-.$/+%. Since letters can be handled, CODE 39 is indispensable in the industrial fields and used in industries such as automotive and electronics. For example, in Germany it is used for pharmaceutical products, but is mainly used in warehousing. In the USA, code 39 was standardized as ANSI MH 10.8 M-1983 and MIL-STD-1189. This standard has been cancelled later and replaced by ANSI/AIM BC1/1995. 

An example of a character encoding

CODE 39 structure

CODE 39 is named for its pattern of bars and spaces, with 3 out of 9 bars and spaces being wide. The basic composition is as follows:

Inter-character gap

Inter-character gap

This table outlines the Code 39 specification. The numeric value assigned to each character (except start/stop) is used in the checksum algorithm described below.

Code 39 characters (and checksum values)

Code 39 is sometimes used with an optional modulo 43 check digit, the code with check digit is referred to as Code 39 mod 43.
Here is how to do the checksum calculation:

1. Take the value (0 through 42) of each character in the barcode excluding start and stop codes.
2. Sum the values.
3. Divide the result by 43.
4. The remainder is the value of the checksum character to be appended.

CODE 39 example

Code 39 Extended is an extended version of Code 39 that supports the ASCII character set. It can encode 128 characters: 0123456789 ABCDEFG HIJKLMNOP QRSTUVWXYZ !#$%&'()*+,-./:;<=>?@[\]^_` {|} abcdefg hijklmnopqrs tuvwxyz, that include 26 uppercase letters (A-Z), 26 lowercase letters (a-z) and special characters with a space.

It is important to note that Extended Code 39 barcode is approximately twice longer than a regular Code 39 barcode. According to ISO 646, these characters are displayed by combining two symbol characters, the first one consists of one of the four characters $ + % / and is followed by one of the 26 letters. If the decoder is programmed with the complete ASCII-character set, only the ASCII-equivalent is transferred and not the symbol character combination.

Code 39 Extended can also be used with an optional modulo 43 checksum, and the code with the check digit looks like “CODE 39 EXTENDED mod 43”.

Code 39 Extended example

Side-by-side comparison of CODE 39 and CODE 39 Extended

Let’s compare the same phrases in different barcodes. In both cases, we see no difference in the first column. But why is there no difference? This is because the characters 0123456789 ABCDEFG HIJKLMNOP QRSTUVWXYZ -. $ / +% in both barcodes are encoded the same way, but if you replace capital letters with lowercase ones, changes appear.

Code 39 and Code 39 extended example

Once again, in CODE 39 Extended, characters are displayed by combining two symbol characters, the first one consists of one of the four characters $ + % / and is followed by one of the 26 letters.

CODE 39 and CODE 39 Extended example

Creation of barcodes in the visual designer

FastReport VCL allows you to use both of previously described barcode types in your reports. Let’s see how to work with them.

In the FastReport VCL designer, add the obCatBarcode component to the report and select the barcode type from the list:

 obCatBarcode

Next, go to the barcode editor:

Barcode editor

Code – area for the numeric value of the barcode;

Type of Bar – the type of the barcode can be changed immediately in the editor without adding a new component to the report;

Calc CheckSum – checksum. All linear barcodes have this property. Remember “miss reading”? We must fight it somehow! This property determines whether the checksum should be calculated automatically. If it is disabled, the checksum must be present in the object text;

Zoom – sets the scaling of the barcode and is used only in conjunction with the “Autosize” property;

Text – enable / disable display of text under the barcode;

Rotation – allows you to set the rotation of the object to one of the fixed angles – 0, 90, 180, 270 degrees.

Click on the F (x) icon and enter the large expression editor.

More details can be found on your own in the FastReport VCL designer or in the documentation. link 1 and link 2

Expression Editor


Settings

Go to the properties of the obCatBarcode component.

The content of the Code field will be transferred to the Expression field. If the Expression field is empty, then the text from the Text field is displayed.

In short, the Text is static text, and the Expression contains the calculated expression, including the value from the data source.

Creating a barcode from the Delphi / Lazarus code

CODE 39
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
uses frxBarcod;
 
procedure TForm1.Button1Click(Sender: TObject);
var bc: TfrxBarcodeView;
begin
 bc :=
TfrxBarcodeView(frxReport1.FindObject('BarCode1'));
{Set the type of the barcode}
bc.BarType := bcCode39;
{Set the fixed barcode value}
 bc.Text := '123456';
{Set the calculated barcode value}
//bc.Expression := '<YourDatasetName."FieldName1"> + <YourDatasetName."FieldName2">';
{Set whether it is necessary to calculate the checksum and add it to the end of the barcode}
bc.CalcCheckSum := False;
{Set the scale at which the barcode will be displayed}
 bc.Zoom := 2;
{Set the angle of the barcode rotation. Can take the following values: 0, 90, 180, 270}
bc.Rotation := 0;
{Set whether to set the width of the barcode depending on its content.}
{If set to False, Zoom will be set to keep the barcode width fixed}
 bc.AutoSize := True;
{Set the barcode background color}
bc.Color := clNone;
{Set the barcode lines color}
bc.ColorBar := clBlack;
{Set whether to display the text at the bottom of the barcode}
 bc.ShowText := True;
 frxReport1.ShowReport();
end;
 

Now we can use the barcode of the CODE 39 standard in our business applications (encode not only numeric, but also alphabetic characters), for example, to output on labels (e.g., in the ZPL format, as well). 

Fast Reports
  • 800-985-8986 (English, US)
  • +4930568373928 (German)
  • +55 19 98147-8148 (Portuguese)
  • info@fast-report.com
  • 901 N Pitt Str #325 Alexandria VA 22314

© 1998-2024 Fast Reports Inc.
Trustpilot