BarCodeWiz Logo

Code 128 Barcodes in Crystal Reports

Code 128 Barcodes in Crystal Reports

  • This tutorial shows how to add Code 128 B barcodes to your Crystal Reports.
  • See the video or simply follow the steps below.

Step 1. Add a new formula

  • In the Field Explorer, right click Formula Fields and click New...

  • Enter a name for the new formula.

Step 2. Locate the Code 128 Functions

  • Ensure the functions are installed. May be listed under one of these three locations:
    Functions > Additional Functions
    Functions > Additional Functions > Visual Basic UFLs (u2lcom.dll)
    Functions > Additional Functions > COM and .NET UFLs (u212com.dll)
  • See here for function descriptions

Step 3a. (For Text Fields): Enter the function name in Formula Editor

     
  • If your data field is text (string), copy the function below and paste it into your report:
stringVar barcodeInput := "Barcode Data 00123456";

stringVar hexStr := Code128BHex(barcodeInput);

local stringVar barcode := "";
local stringVar hexVals := "0123456789ABCDEF";
local numberVar hexStrLength := Length(hexStr);
local numberVar i;
for i := 1 to hexStrLength step 2 do
(
    local stringVar byteAsHex := Mid(hexStr, i, 2);
    local numberVar byte := Int( (Instr( hexVals, Mid(byteAsHex, 1, 1))-1) * 16 + Instr( hexVals, Mid(byteAsHex, 2, 1))-1);
    barcode := barcode & ChrW(byte);
);

barcode;




  •  Click on Save and close. Continue to Step 4.

Step 3b. (For Numeric Fields): Enter the function name in Formula Editor

  • If your data field is numeric, it must be converted to text. This is done using the Crystal Function ToText().
  • Copy the formula text below and paste it into your report:

stringVar barcodeInput := ToText( 12345678, 0, '');

stringVar hexStr := Code128BHex(barcodeInput);

local stringVar barcode := "";
local stringVar hexVals := "0123456789ABCDEF";
local numberVar hexStrLength := Length(hexStr);
local numberVar i;
for i := 1 to hexStrLength step 2 do
(
    local stringVar byteAsHex := Mid(hexStr, i, 2);
    local numberVar byte := Int( (Instr( hexVals, Mid(byteAsHex, 1, 1))-1) * 16 + Instr( hexVals, Mid(byteAsHex, 2, 1))-1);
    barcode := barcode & ChrW(byte);
);

barcode;

 


  •  Click on Save and close.

Step 4. Add a barcode to the report

  • Drag the formula from Field Explorer to the report

  • Change the font properties to:
    Font Name: BCW_Code128B_2
    Font Size: 24

The report is now ready

  • Click on Preview to see or print it.

Code 128 Fonts Functions in Crystal Reports


Code128Auto()

  • Code128Auto() Encodes data in the most efficient way possible, using a combination of subsets if necessary. Supports all 128 ASCII characters.
  • This function should be used with one of the following fonts:
    BCW_Code128_1 through BCW_Code128_6 (does not show human readable text)
  • This function requires the use of a barcode font without human readable text. However, the text can easily be displayed in a separate formula field with a font such as Arial.
  • To encode a control character, enter it in the format: ^000, where 000 is its digital ASCII value. For example, ABC^009 encodes ABC followed by TAB. To encode FNC1, enter: ^F1

Code128B()

  • Code128B() Encodes data using Code 128 Subset B only. It supports numbers, upper and lower-case letters, space, and the following characters: !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
  • This function should be used with one of the following fonts:
    BCW_Code128B_1 through BCW_Code128B_6 (shows human-readable text under barcode)
    BCW_Code128_1 through BCW_Code128_6 (does not show human readable text)
  • It is possible to encode control characters using the function Code128B() by temporarily shifting to Subset A. This process is automatic.
  • To encode a control character, enter it in the format: ^000, where 000 is its digital ASCII value. For example, ABC^009 encodes ABC followed by TAB. To encode FNC1, enter: ^F1

Code128C()

  • Code128C() Encodes data using Code 128 Subset C. It supports numbers only and must contain an even number of digits.
  • The digits are encoded in pairs of two, resulting in a barcode about half as wide as subset A or B.
  • This function should be used with one of the following fonts:
    BCW_Code128C_1 through BCW_Code128C_6 (shows human-readable text under barcode)
    BCW_Code128_1 through BCW_Code128_6 (does not show human readable text)
  • To encode FNC1, enter: ^F1