BarCodeWiz Logo

GS1-128 Barcodes in Crystal Reports

  • This tutorial shows how to create GS1-128 barcodes using BarCodeWiz Code 128 Fonts in Crystal Reports.
  • GS1-128 barcodes consist of two parts: barcode and specially formatted text under or above the barcode. This is accomplished using two Formula Fields.
  • See the video or simply follow the steps below.

Step 1. Add a Formula Field to display the barcode

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

  • Enter a name for the new barcode field

Step 2. Enter the GS1-128 Formula

     
  •  Copy / paste the following formula into Formula Editor

    stringVar barcodeInput := "(00)00614141123456789(3103)000123";
    
    stringVar hexStr := GS1128Hex(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;

 


Step 3. Add a second Formula Field, to display the human-readable text

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

  • Enter a name for the new text field

  • Enter the formula to format the text
    GS1128FormatText("(00)00614141123456789(3103)000123")
  • This formula formats text by inserting parentheses (if not supplied), spaces, and any necessary check digits.
  • See all GS1-128 function descriptions
  • Click Save and close.

Step 4. Add barcode to the report

  • Drag and drop both fields onto the Details section of the report.

  • Change the font name and size of the barcode field.
  • Be sure to use one of the fonts without text underneath:
    BCW_Code128_1 through BCW_Code128_6

  • Extend both fields to prevent from being cut off.

That's all! The report is ready to preview and print.

GS1-128 Functions in Crystal Reports


GS1128(String)

  • GS1128() Converts text into a proper GS1-128 (EAN-128) barcode. It accepts input in two possible formats (both formats produce the same barcode)
  • Format 1, with parentheses: GS1128("(XX)YYYYYY(XX)YYYYYY") - This is the preferred option. It adds any necessary FNC1 characters. It also calculates and autocorrects check digits.
    Example: GS1128("(10)12345(30)123") or GS1128({table.textField})
  • Format 2, with no parentheses: GS1128("XXYYYYYYXXYYYYYY") - This format requires the FNC1 characters to be added manually. To encode FNC1, enter: ^F1
    Example: GS1128("1012345^F130123") or GS1128({table.textField})
  • This function should be used with one of the following six fonts: BCW_Code128_1 through BCW_Code128_6
    It requires the use of a barcode font without human readable text. However, the text can easily be displayed in a separate formula field using a font such as Arial.

GS1128FormatText(String)

  • This function formats the human readable portion of the barcode (the text). It adds parentheses and spaces. It also calculates and adds any necessary MOD10 check digits. Incorrect check digits are corrected automatically.
  • Example usage: GS1128FormatText("(01)9501234567890(3103)000123")
    Example Output: (01) 9 50 12345 67890 3 (3103) 000123

GS1128FormatText2(String)

  • This function formats the human readable portion of the barcode (the text). It adds parentheses. It does not add spaces. It also calculates and adds any necessary MOD10 check digits. Incorrect check digits are corrected automatically.
  • Example usage: GS1128FormatText2("(01)9501234567890(3103)000123")
    Example Output: (01)95012345678903(3103)000123

GS1128FormatText3(String)

  • This function formats the human readable portion of the barcode (the text) by grouping-by-4 digits. It calculates and adds any necessary MOD10 check digits. Incorrect check digits are corrected automatically.
  • Example usage: GS1128FormatText3("(01)9501234567890(3103)000123")
    Example Output: 0195 0123 4567 8903 3103 0001 23

GS1128FormatText4(String)

  • This function formats the human readable portion of the barcode (the text). It calculates and adds any necessary MOD10 check digits. Incorrect check digits are corrected automatically.
  • Example usage: GS1128FormatText4("(01)9501234567890(3103)000123")
    Example Output: 01950123456789033103000123

GS1128FormatTextCustom(String, String)

  • This function formats the human readable portion of the barcode (the text) in a user-defined format. It calculates and adds any necessary MOD10 check digits. Incorrect check digits are corrected automatically.
  • Example usage: GS1128FormatTextCustom("(01)9501234567890(3103)000123","??? ???? ?-?-?-??????????-??????")
    Example Output: 019 5012 3-4-5-6789033103-000123