The 128 code
This complex code allows the coding of the 128 ASCII characters. The result is very dense, in particular for the coding of the numerical values. It is used amongst other things on certain sheet of social security (in France) and certain transport label to register the SSCC number. (Identifier of the parcel)
Let's learn encoding system.
- The width of a slim bar is named the module.
- There are bars of 1, 2, 3 or 4 modules; equally for the spaces.
- There are 107 patterns, each is coded with 11 modules including 3 bars and 3 spaces (The STOP pattern have 4 bars).
- There are 3 tables giving the character or the function affected to each pattern.
* Table A contains the capital letters, the digits, the punctuations, some control codes and special codes.
* Table B contains capital and lower case letters, the digits, the punctuations and special codes.
* Table C contains pairs of digits (Allowing to double the density) and special codes.
- Quiet zones of at least 10 modules are requested on the left and on the right.
- There is a START character at the beginning of the code. There are 3 START characters fixing the table used for the start.
- The code ends with a STOP character.
- Some special characters (99, 100 & 101) make it possible to pass from one table to an other; the SHIFT character (98) switch the next character between tables A & B.
- The function codes (FNC1 a FNC4) aren't all defined.
- A checksum must be added; its value is calculated by adding up the value of the START then the value of each pattern multiplied by its row; then by taking the remainder of the division of this sum by 103.
- In the following array a bar module is symbolized by "1" and a space module by "0".
- The columns "ASCII Code" and "Character" indicate the place of the patterns in the font "code128.ttf" (See further)
- The character n 0 (Space) is obtained with the code 32 or with the code 212 because some programming tools cannot use code 32.
Exemple of checksum with use of table B for : ZB65
104 + (1 x 58) + (2 x 34) + (3 x 22) + (4 x 21) = 380
380 / 103 = 3, remainder 71 which is the value of the key.
Version 2.00 of the font : The code of characters 95 and following was modified compared to the version 1.00. The encoding function was modified consequently.
Bar code making.
Since we can create the bar code pattern it remains us to draw it on the screen and to print it on a paper sheet. Two approaches are possible :
- The graphic method where each bar is "drawn" as a full rectangle. This method enable to compute the width of each bar with a one pixel precision and so we can work with widths which are perfect multiple of the used device pixel. This give us a good accuracy specially if the device have a low density as it's the case with screens and inkjet printers. This method require special programming routines and does not allow to make bar codes with a current software.
- The special font in which each character is replaced by a bar code. This method allow the use of any software like a text processing or a spreadsheet. (For example OpenOffice, the free clone of MSoffice !) The scale settings according to the selected size can bring away small misshaping of the bar drawing. With a laser printer there's no probs.
All the found 128 barcodes on the net (Incomplete demonstration font) aren't free, several times expensive, and with uncertain quality; the width module isn't always permanent in the font definition. I've decided consequently to draw entirely a 128 font and to propose it for download. I test it on a laser printer with size 17, what gives a small barcode with a width of about 1,7 mm/car, result : reading at 100% ! On a good inkjet printer, we can go down (He yes !) to the size 15 what give a character width of 1,5mm.
The font " code128.ttf "
This font contain the 107 patterns of the code. The START and STOP codes include the margins.
Copy this file
Structure of a 128 barcode
A 128 barcode will be build up in the following way :
- One of the three START code, generally START B.
- As many characters as necessary, special codes makes it possible to pass from one table to an other. An intelligent algorithm will allow to use one or more tables giving the barcode shortest possible.
- A checksum.
- A STOP code.
A small program to test all that
Here is a small program
This test program does not manage the ASCII control codes, it use the tables B & C with optimization length of the code obtained.
The Code128$ function can be re-used in an other program written with Visual Basic 6 ; it can also be copied as it is in a VBA macro linked to an Excel or Word document. (See the note about the version)
|Public Function Code128$(chaine$) 'V 2.0.0 'Parametres : une chaine 'Parameters : a string 'Retour : * une chaine qui, affichee avec la police CODE128.TTF, donne le code barre ' * une chaine vide si parametre fourni incorrect 'Return : * a string which give the bar code when it is dispayed with CODE128.TTF font ' * an empty string if the supplied parameter is no good Dim i%, checksum&, mini%, dummy%, tableB As Boolean Code128$ = "" If Len(chaine$) > 0 Then 'Verifier si caracteres valides 'Check for valid characters For i% = 1 To Len(chaine$) Select Case Asc(Mid$(chaine$, i%, 1)) Case 32 To 126, 203 Case Else i% = 0 Exit For End Select Next 'Calculer la chaine de code en optimisant l'usage des tables B et C 'Calculation of the code string with optimized use of tables B and C Code128$ = "" tableB = True If i% > 0 Then i% = 1 'i% devient l'index sur la chaine / i% become the string index Do While i% <= Len(chaine$) If tableB Then 'Voir si interessant de passer en table C / See if interesting to switch to table C 'Oui pour 4 chiffres au debut ou a la fin, sinon pour 6 chiffres / yes for 4 digits at start or end, else if 6 digits mini% = IIf(i% = 1 Or i% + 3 = Len(chaine$), 4, 6) GoSub testnum If mini% < 0 Then 'Choix table C / Choice of table C If i% = 1 Then 'Debuter sur table C / Starting with table C Code128$ = Chr$(210) Else 'Commuter sur table C / Switch to table C Code128$ = Code128$ & Chr$(204) End If tableB = False Else If i% = 1 Then Code128$ = Chr$(209) 'Debuter sur table B / Starting with table B End If End If If Not tableB Then 'On est sur la table C, essayer de traiter 2 chiffres / We are on table C, try to process 2 digits mini% = 2 GoSub testnum If mini% < 0 Then 'OK pour 2 chiffres, les traiter / OK for 2 digits, process it dummy% = Val(Mid$(chaine$, i%, 2)) dummy% = IIf(dummy% < 95, dummy% + 32, dummy% + 105) Code128$ = Code128$ & Chr$(dummy%) i% = i% + 2 Else 'On n'a pas 2 chiffres, repasser en table B / We haven't 2 digits, switch to table B Code128$ = Code128$ & Chr$(205) tableB = True End If End If If tableB Then 'Traiter 1 caractere en table B / Process 1 digit with table B Code128$ = Code128$ & Mid$(chaine$, i%, 1) i% = i% + 1 End If Loop 'Calcul de la cle de controle / Calculation of the checksum For i% = 1 To Len(Code128$) dummy% = Asc(Mid$(Code128$, i%, 1)) dummy% = IIf(dummy% < 127, dummy% - 32, dummy% - 105) If i% = 1 Then checksum& = dummy% checksum& = (checksum& + (i% - 1) * dummy%) Mod 103 Next 'Calcul du code ASCII de la cle / Calculation of the checksum ASCII code checksum& = IIf(checksum& < 95, checksum& + 32, checksum& + 105) 'Ajout de la cle et du STOP / Add the checksum and the STOP Code128$ = Code128$ & Chr$(checksum&) & Chr$(211) End If End If Exit Function testnum: 'si les mini% caracteres a partir de i% sont numeriques, alors mini%=0 'if the mini% characters from i% are numeric, then mini%=0 mini% = mini% - 1 If i% + mini% <= Len(chaine$) Then Do While mini% >= 0 If Asc(Mid$(chaine$, i% + mini%, 1)) < 48 Or Asc(Mid$(chaine$, i% + mini%, 1)) > 57 Then Exit Do mini% = mini% - 1 Loop End If Return End Function|
In order to test this function with Excel, here's a sample file : and with Open Office :
Since the first publication of this page, I'd received numbered versions in different languages :
PL/SQL pour Oracle
Franck Odouard &
The EAN.UCC 128 codes.
These are codes 128 whose content is standardized and correspond to a use in the field of logistic. An EAN128 code starts with the Fnc1 character followed by one or several fields of data. Each field starts with an AI (Application Identifier) which announce the field content (Number of parcel or durability date for examples) followed by the data themselves. These datas are length fixed or variable, numerical or alphanumeric, with or without checksum and all this according to each AI. If a field is with variable length, that the maximum length isn't used and that it is not the last field, then it must be followed by a Fnc1 character. Some AI requires that the datas are followed by a checksum; this one is computed in the following way :
The digits are numbered from right to left, then we compute X the sum of even digits and Y the sum of odd digits.
I have written a small program allowing to create easily EAN128 codes and holding account of these characteristics.
Confused about barcodes? Don’t be.
In the simplest definition, barcodes are simply a combination of lines and spaces that represent specific characters. While barcodes have similar characteristics as fonts (sizes, styles and languages), they are created by various algorithms for each “symbology” (language). Therefore, users who need code-specific, verifiable fonts for compliance labeling can be in trouble if they simply download a “barcode font” from the internet. Barcodes work much like human readable fonts, but are read by a machine—either a barcode scanner, mobile computer, imager or verifier. Because they are machine readable and used by millions of companies across the world, there are global standards established for the structure of barcode data, along with standardized measurements for the quality, or readability, of the barcode. Learn more about Barcode Solutions.
Have Questions about Barcodes and Barcoding Technology?
As a complete system integrator, Inovity has the experience and knowledge to bring best-in-class solutions to our clients. We can improve the productivity and efficiency of your business and make your operation more successful and more profitable.
Call us today and speak with a Systems Consultant or fill out this brief form, and we’ll have Systems Consultant contact you. If you don’t know where to start, we’re your first step.