French version

The 3 of 9 code.



This code easy to use allows the coding of 43 characters : 10 digits, 26 capital letters, the symbols $ % + -. / and the space. The extend mode makes it possible to code the 128 ASCII characters ; in this mode characters added compared to the "simple" mode are coded with 2 characters.


Let's learn encoding system.
Character Value Pattern 0 0 101000111011101 1 1 111010001010111 2 2 101110001010111 3 3 111011100010101 4 4 101000111010111 5 5 111010001110101 6 6 101110001110101 7 7 101000101110111 8 8 111010001011101 9 9 101110001011101 A 10 111010100010111 B 11 101110100010111 C 12 111011101000101 D 13 101011100010111 E 14 111010111000101
Character Value Pattern F 15 101110111000101 G 16 101010001110111 H 17 111010100011101 I 18 101110100011101 J 19 101011100011101 K 20 111010101000111 L 21 101110101000111 M 22 111011101010001 N 23 101011101000111 O 24 111010111010001 P 25 101110111010001 Q 26 101010111000111 R 27 111010101110001 S 28 101110101110001 T 29 101011101110001
Character Value Pattern U 30 111000101010111 V 31 100011101010111 W 32 111000111010101 X 33 100010111010111 Y 34 111000101110101 Z 35 100011101110101 - 36 100010101110111 . 37 111000101011101 Space 38 100011101011101 $ 39 100010001000101 / 40 100010001010001 + 41 100010100010001 % 42 101000100010001       *   100010111011101

Exemple of checksum for : ZB65732
35 + 11 + 6 +5 +7 +3 +2 = 69
69 / 43 = 1, remainder 26 which corresponds to the letter Q
New code with the checksum : ZB65732Q


The extend mode.

The charaters not forming part of the simple mode are coded with one of the 4 prefix % $ / +  followed by a basic character according to the following table. To literally use the charaters which are used as prefix or the symbol * it will be necessary to use a coding on 2 characters.

Character to be produced Sequence to be used NUL %U SOH $A STX $B ETX $C EOT $D ENQ $E ACK $F BEL $G BS $H HT $I LF $J VT $K FF $L CR $M SO $N SI $O DLE $P DC1 $Q DC2 $R DC3 $S DC4 $T NAK $U SYN $V ETB $W CAN $X EM $Y SUB $Z ESC %A FS %B GS %C RS %D US %E SPACE SPACE ! /A " /B # /C $ /D % /E & /F ' /G ( /H ) /I * /J
Character to be produced Sequence to be used + /K , /L - - . . / /O 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 : /Z ; %F < %G = %H > %I ? %J @ %V A A B B C C D D E E F F G G H H I I J J K K L L M M N N O O P P Q Q R R S S T T U U
Character to be produced Sequence to be used V V W W X X Y Y Z Z [ %K \ %L ] %M ^ %N _ %O ` %W a +a b +b c +c d +d e +e f +f g +g h +h i +i j +j k +k l +l m +m n +n o +o p +p q +q r +r s +s t +t u +u v +v w +w x +x y +y z +z { %P | %Q } %R ~ %S DEL %T    

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 3 of 9 font and offer it for download. I tested it on a laser printer with size 11, what gives a small barcode with a width of about 1,6 mm/car, result : reading at 100% ! On a good inkjet printer, we must go up to the size 15 which gives a character width of 2,1mm.


La police " code39.ttf "

This font contain the 43 basic charactersand the delimitor under the symbol   . Each character ends with a fin white bar of separation.

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


Structure of a 3 of 9 barcode.

A 3 of 9 barcode will be build up in the following way :

A small program to test basic mode.

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

Setup file :

ZIP file without setup :

This test program manages neither the extend mode nor the checksum.

The Code39$ 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 Code39$(chaine$)
  'V 1.0.0
  'Paramètres : une chaine
  'Retour : * une chaine qui, affichée avec la police CODE39.TTF, donne le code barre
  '         * une chaine vide si paramètre fourni incorrect
  Dim i%
  Code39$ = ""
  If Len(chaine$) > 0 Then
  'Vérifier si caractères valides
    For i% = 1 To Len(chaine$)
      Select Case Asc(Mid$(chaine$, i%, 1))
      Case 32, 36, 37, 43, 45 To 57, 65 To 90
      Case Else
        i% = 0
        Exit For
      End Select
    Next
    If i% > 0 Then
      Code39$ = "*" & chaine$ & "*"
    End If
  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   Visual Foxpro Emile MAITREJEAN Delphi Jean-Camille POPULUS Delphi Francisco FERNANDEZ



Do you like this page ?

Is it useful for you ?
Click here !