
|
This code used on all current consumer products allow a 12 digits code, the thirteenth digit is a control key that we'll must generate. Before going into technique, two smalls evasions.
The UPC-A bar code type used in U.S.A. It has only 11 digits and the key. It's in fact an EAN13 code with
the first digit to zero and with a lightly different custom. The UPC-A code
type is a subset of the EAN13 type.
These two barcodes are identicals, we have put a zero before
the UPC-A
code to obtain the EAN13 code but the bar pattern is tightly identical. |
Digits sense. - 2 digits for the country code or system code
|
|
The digits are numbered from right to left; Example : 978020113447 |
Let's symbolize the bar module by "1" and the space module by "0"
The digits are converted with one of the 3 tables below ; the codes of tables A and B begin with a space whereas ones of table C begin with a bar.
|
Digit |
Table A |
Table B |
Table C |
|
0 |
0001101 |
0100111 |
1110010 |
|
1 |
0011001 |
0110011 |
1100110 |
|
2 |
0010011 |
0011011 |
1101100 |
|
3 |
0111101 |
0100001 |
1000010 |
|
4 |
0100011 |
0011101 |
1011100 |
|
5 |
0110001 |
0111001 |
1001110 |
|
6 |
0101111 |
0000101 |
1010000 |
|
7 |
0111011 |
0010001 |
1000100 |
|
8 |
0110111 |
0001001 |
1001000 |
|
9 |
0001011 |
0010111 |
1110100 |
The first digit is not coded, each 6 following digit is converted either
by table A or by the table B and that according to the first digit. The 6 last
digits are converted by the table C.
A new table indicates the use of table
A or B according to the number 1 digit.
|
According to digit 1 |
Digit 2 |
Digit 3 |
Digit 4 |
Digit 5 |
Digit 6 |
Digit 7 |
|
0 |
A |
A |
A |
A |
A |
A |
|
1 |
A |
A |
B |
A |
B |
B |
|
2 |
A |
A |
B |
B |
A |
B |
|
3 |
A |
A |
B |
B |
B |
A |
|
4 |
A |
B |
A |
A |
B |
B |
|
5 |
A |
B |
B |
A |
A |
B |
|
6 |
A |
B |
B |
B |
A |
A |
|
7 |
A |
B |
A |
B |
A |
B |
|
8 |
A |
B |
A |
B |
B |
A |
|
9 |
A |
B |
B |
A |
B |
A |
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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 :
All the found EAN13 bar codes 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 an EAN13 font and to propose it for download. I test it on a laser printer with size 14, what gives a very small barcode with a width of about 13 mm, result : reading at 100% ! On a good inkjet printer, this same size of 14 work very well.
This font contain the 5 sets of the 10 digits for the 3 tables A, B and C learned above and 2 tables for the first digit (Table D & E)
The following table indicates the correspondence between the drawned bar code and the typed letter (ASCII code between bracket)
|
Copy this file |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
The alone start delimiter (Code 58) and the table E were
added for the SAGE software
user who will have to then configure in their software the EAN13
encoding font table as follows :
|
An EAN13 barcode will be build up in the following way :
|
|
Here is a small program
|
The EAN13$ function can be re-used in any other Visual Basic 6 program ; it can also be recopied just as it in a VBA macro linked to an Excel or Word document.
Public Function ean13$(chaine$)
'Cette fonction est regie par la Licence Generale Publique Amoindrie GNU (GNU LGPL)
'This function is governed by the GNU Lesser General Public License (GNU LGPL)
'V 1.1.1
'Parametres : une chaine de 12 chiffres
'Parameters : a 12 digits length string
'Retour : * une chaine qui, affichee avec la police EAN13.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 EAN13.TTF font
' * an empty string if the supplied parameter is no good
Dim i%, checksum%, first%, CodeBarre$, tableA As Boolean
ean13$ = ""
'Verifier qu'il y a 12 caracteres
'Check for 12 characters
If Len(chaine$) = 12 Then
'Et que ce sont bien des chiffres
'And they are really digits
For i% = 1 To 12
If Asc(Mid$(chaine$, i%, 1)) < 48 Or Asc(Mid$(chaine$, i%, 1)) > 57 Then
i% = 0
Exit For
End If
Next
If i% = 13 Then
'Calcul de la cle de controle
'Calculation of the checksum
For i% = 12 To 1 Step -2
checksum% = checksum% + Val(Mid$(chaine$, i%, 1))
Next
checksum% = checksum% * 3
For i% = 11 To 1 Step -2
checksum% = checksum% + Val(Mid$(chaine$, i%, 1))
Next
chaine$ = chaine$ & (10 - checksum% Mod 10) Mod 10
'Le premier chiffre est pris tel quel, le deuxieme vient de la table A
'The first digit is taken just as it is, the second one come from table A
CodeBarre$ = Left$(chaine$, 1) & Chr$(65 + Val(Mid$(chaine$, 2, 1)))
first% = Val(Left$(chaine$, 1))
For i% = 3 To 7
tableA = False
Select Case i%
Case 3
Select Case first%
Case 0 To 3
tableA = True
End Select
Case 4
Select Case first%
Case 0, 4, 7, 8
tableA = True
End Select
Case 5
Select Case first%
Case 0, 1, 4, 5, 9
tableA = True
End Select
Case 6
Select Case first%
Case 0, 2, 5, 6, 7
tableA = True
End Select
Case 7
Select Case first%
Case 0, 3, 6, 8, 9
tableA = True
End Select
End Select
If tableA Then
CodeBarre$ = CodeBarre$ & Chr$(65 + Val(Mid$(chaine$, i%, 1)))
Else
CodeBarre$ = CodeBarre$ & Chr$(75 + Val(Mid$(chaine$, i%, 1)))
End If
Next
CodeBarre$ = CodeBarre$ & "*" 'Ajout separateur central / Add middle separator
For i% = 8 To 13
CodeBarre$ = CodeBarre$ & Chr$(97 + Val(Mid$(chaine$, i%, 1)))
Next
CodeBarre$ = CodeBarre$ & "+" 'Ajout de la marque de fin / Add end mark
ean13$ = CodeBarre$
End If
End If
End Function
|
Since the first publication of this page, I'd received numbered versions in different languages :
|
Language |
Auteur |
|
|
Jean-Louis HUVE |
||
|
Visual Foxpro |
Emile MAITREJEAN |
|
|
Delphi |
John SWIJSEN |
|
|
C# |
Russell SAYERS |
|
|
Perl |
Simone FIORAVANTI |
|
|
Axapta |
Soe JESPER |
|
EAN 8 code It resemble to code EAN 13 very much. It has 7 digits and
a checksum computed exactly in the same way as for code EAN13. The
delimitors left (We shall use ASCII
58), middle and right are the same ones. The first 4 digits are
build with table A and the last 4 ones with the table C.
Public Function EAN8$(chaine$)
'V 1.0.0
'Parametres : une chaine de 7 chiffres
'Parameters : a 7 digits length string
'Retour : * une chaine qui, affichee avec la police EAN13.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 EAN13.TTF font
' * an empty string if the supplied parameter is no good
Dim i%, checksum%, first%, CodeBarre$, tableA As Boolean
EAN8$ = ""
'Verifier qu'il y a 7 caracteres
'Check for 7 characters
If Len(chaine$) = 7 Then
'Et que ce sont bien des chiffres
'And they are really digits
For i% = 1 To 7
If Asc(Mid$(chaine$, i%, 1)) < 48 Or Asc(Mid$(chaine$, i%, 1)) > 57 Then
i% = 0
Exit For
End If
Next
If i% = 8 Then
'Calcul de la cle de controle
'Calculation of the checksum
For i% = 7 To 1 Step -2
checksum% = checksum% + Val(Mid$(chaine$, i%, 1))
Next
checksum% = checksum% * 3
For i% = 6 To 1 Step -2
checksum% = checksum% + Val(Mid$(chaine$, i%, 1))
Next
chaine$ = chaine$ & (10 - checksum% Mod 10) Mod 10
'Les 4 premier chiffre viennent de la table A
'The first 4 digits come from table A
CodeBarre$ = ":" 'Ajout marque de debut / Add start mark
For i% = 1 To 4
CodeBarre$ = CodeBarre$ & Chr$(65 + Val(Mid$(chaine$, i%, 1)))
Next
CodeBarre$ = CodeBarre$ & "*" 'Ajout separateur central / Add middle separator
For i% = 5 To 8
CodeBarre$ = CodeBarre$ & Chr$(97 + Val(Mid$(chaine$, i%, 1)))
Next
CodeBarre$ = CodeBarre$ & "+" 'Ajout de la marque de fin / Add end mark
EAN8$ = CodeBarre$
End If
End If
End Function
|
|
Do you like this
page ? Click here ! |