French version

The 2 of 5 interleaved code.



This code allows only the coding of digits. They are coded 2 by 2 so the number of digits must be even.

Let's learn encoding system.
Value Encoding 0 NNWWN 1 WNNNW 2 NWNNW 3 WWNNN 4 NNWNW 5 WNWNN 6 NWWNN 7 NNNWW 8 WNNWN 9 NWNWN

Exemple of checksum for : 65732
(2 + 7 + 6) x 3 + 3 + 5 = 53 ---> M = 60
60 - 53 = 7
New code with the checksum : 657327 (Note that the number of digits including checksum is even.)


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 possibles : Most fonts for barcodes 3 of 9 found on the net (incomplete demonstration fonts) are paid for (sometimes very expensive) and of dubious quality; the width of the modules is not always constant in the definition of the font. So I decided to completely design a 2 of 5 interleaved font and offer it for download. I tested it on a laser printer with size 15, what gives a small barcode with a width of about 1,2 mm/digit, result : reading at 100% ! On a good inkjet printer, we can use the same size 15 for the same result.

The font " code25I.ttf "
Since 2 of 5 interleaved barcodes encode pairs of digit my font contain the 100 pairs from 00 to 99. 2 additionnal characters are reserved for start and end symbol.
Pair of digits ASCII code Character Pattern 00 0033 ! NNNNWWWWNN 01 0034 " NWNNWNWNNW
.../...
93 0126 ~ NWWWNNWNNN 94 0195 Ã NNWNNWWNNW
.../...
99 0200 È NNWNNNWWNW Début 0201 É NNNN Fin 0202 Ê WNN


Copy this file in the font directory, often named : \Windows\Fonts

Structure of a 2 of 5 interleaved barcode.
A 2 of 5 interleaved barcode will be build up in the following way :
A small test program.

Here is a small program written with Visual Basic 6.
The setup file copy the program, Visual Basic
dependencies, source files and the font.

Setup file :

ZIP file without setup :

The Code25I$ function can be re-used in any other program written with Visual BASIC 6; it can also be copied just as it is in a VBA macro linked to an Excel or Word document.

Public Function Code25I$(chaine$, Optional key As Boolean)
  'V 2.0.0
  'Paramètres : * une chaine
  '             * un drapeau vrai si une clé doit être ajoutée
  'Parameters : * a string
  '             * a flag true if a key must be added
  'Retour : * une chaine qui, affichée avec la police CODE25I.TTF, donne le code barre
  '         * une chaine vide si paramètre fourni incorrect
  'Return : * a string which give the bar code when it is dispayed with CODE25I.TTF font
  '         * an empty string if the supplied parameter is no good
  Dim i%, checksum&, dummy%
  Code25I$ = ""
  If Len(chaine$) > 0 Then
    'Vérifier si caractères valides
    'Check for valid characters
    For i% = 1 To Len(chaine$)
      If Asc(Mid$(chaine$, i%, 1)) < 48 Or Asc(Mid$(chaine$, i%, 1)) > 57 Then Exit Function
    Next
    'Ajouter si nécessaire la clé
    'Add if necessary the checksum
    If key Then
      For i% = Len(chaine$) To 1 Step -2
        checksum& = checksum& + Val(Mid$(chaine$, i%, 1))
      Next
      checksum& = checksum& * 3
      For i% = Len(chaine$) - 1 To 1 Step -2
        checksum& = checksum& + Val(Mid$(chaine$, i%, 1))
      Next
      chaine$ = chaine$ & (10 - checksum& Mod 10) Mod 10
    End If
    'Vérifier si la longueur est paire
    'Check if the length is odd
    If Len(chaine$) \ 2 <> Len(chaine$) / 2 Then Exit Function
    'Calculer la chaine de code
    'Calculation of the code string
    For i% = 1 To Len(chaine$) Step 2
      dummy% = Val(Mid$(chaine$, i%, 2))
      dummy% = IIf(dummy% < 94, dummy% + 33, dummy% + 101)
      Code25I$ = Code25I$ & Chr$(dummy%)
    Next
    'Ajoute START et STOP / Add START and STOP
    Code25I$ = Chr$(201) & Code25I$ & Chr$(202)
  End If
End Function			
			

Sample file for Excel
File for Libre Office
Since the first publication of this page, I'd received numbered versions in different languages :

Language Author   Delphi Francisco FERNANDEZ Visual Foxpro Cédric THIVIND C# Pauline


Do you like this page ?

Is it useful for you ?
Click here !