SQLServerCentral Article

SQL Server Barcodes

,

Introduction

The purpose of the Free Barcoding Toolkit is to provide tools necessary to generate Code 39, Extended Code 39 and Code 128 barcodes as simply as possible. The tools provided include True Type Fonts and a .NET Barcode Generator.

By themselves, the True Type fonts can be used to manually generate barcodes in word processing or other applications. When used with the .NET Barcode Generator, check digits and graphical barcodes which can be cut and pasted into other applications can be generated. Using the techniques outlined in the .NET Barcode Generator source code, simple .NET barcode user controls and other applications can be crafted fairly easily.

Download the Barcode Toolkit

Code 39

Code 39 was one of the first alphanumeric barcode symbologies. It is easy to use, recognized by most barcode scanners, and provides a simple solution for barcoding internal business documents and other items. The basic set of Code 39 symbols includes letters A - Z, numbers 0 - 9, hypen (-), period (.), dollar sign ($), slash (/), plus sign (+), percent sign (%), asterisk (*) and the space character.

In Code 39 barcodes, the asterisk is used as the start and stop character, so all Code 39 barcodes must begin and end with an asterisk.

Code 39 utilizes a Mod 43 check digit when a check digit is required. Check Digit Calculation is described below. The .NET Barcode Generator application included with the Barcoding Toolkit will generate Code 39 Check Digits automatically.

Additionally, Code 39 defines an extended character set. These codes are generated by prefixing the standard codes above with the +, %, $ and / characters. The complete list of Code 39 and Extended Code 39 barcode characters is also listed in the Code 39 Character Table. Your barcode scanner will need to be able to recognize the Extended Code 39 barcode set in order to make use of the Extended Code 39 set.

The Barcode Toolkit includes a Code 39 barcode True Type font. This font can be used in Microsoft Word, or any other application that recognizes True Type fonts, to generate barcodes. Note that because Microsoft Word automatically displays a space character at the end of a line, the barcode symbol for the space character is generated in this character set by using the Underscore (_) character instead of the space bar.

A sample barcode generated via the .NET Barcode Generator is shown below:

The actual barcode text generated, with Check Digit, is *SQLW*.

Basic Code 39 Character Set

The Basic Code 39 Character Set table describes the basic Code 39 characters. The Value is the value assigned to each character, for checksum calculations as described below. The ASCII Char is the ASCII character produced by the scanner when it reads the barcode. The Font Char is the Character used to generate the barcode symbol.

ValueASCII CharFont CharValueASCII CharFont Char
00022MM
11123NN
22224OO
33325PP
44426QQ
55527RR
66628SS
77729TT
88830UU
99931VV
10AA32WW
11BB33XX
12CC34YY
13DD35ZZ
14EE36--
15FF37..
16GG38SPACE_
17HH39$$
18II40//
19JJ41++
20KK42%%
21LLn/a**

Extended Code 39 Character Set

Code 39 defines an Extended Character Set which consists of combinations of "shift" characters ($, /, +, %) with other characters from the Basic Code 39 Character set. The Extended Code 39 character set includes the Basic Code 39 characters, plus the extended set in the table below. A barcode scanner that can read extended Code 39 Character sets can convert these extended codes to their equivalent ASCII characters.

EncodingASCII CharEncodingASCII CharEncodingASCII Char
$ASOH%G<+Cc
$BSTX%H=+Dd
$CETX%I>+Ee
$DEOT%J?+Ff
$EENQ%K[+Gg
$FACK%L\+Hh
$GBEL%M]+Ii
$HBS%N^+Jj
$IHT%O_+Kk
$JLF%P{+Ll
$KVT%Q|+Mm
$LFF%R}+Nn
$MCR%S~+Oo
$NSO%UNUL+Pp
$OSI%V@+Qq
$PDLE%W`+Rr
$QDC1%T,%X,%Y,%ZDEL+Ss
$RDC2/A!+Tt
$SDC3/B"+Uu
$TDC4/C#+Vv
$UNAK/D$+Ww
$VSYN/E%+Xx
$WETB/F&+Yy
$XCAN/G'+Zz
$YEM/H(
$ZSUB/I)
%AESC/J*
%BFS/K+
%CGS/L,
%DRS/Z:
%EYS+Aa
%F;+Bb

Code 39 Check Digits

Code 39 uses a "Mod 43" check digit calculation. To calculate a Code 39 check digit, perform the following steps:

  1. Eliminate the leading and trailing asterisks (*) from your Code 39 barcode string.
  2. Assign each character a numeric value from the Basic Code 39 character set table above.
  3. Add all of the numeric values together and divide by 43.
  4. The remainder is your check digit value. You then locate the check digit character by its value in the Basic Code 39 table, and append it to the barcode string before the final closing asterisk.

Code 128

Code 128 was designed as a more compact barcode symbology than Code 39, and it can be used to represent nearly the entire ASCII character set. It is divided into three different sets:

  • Set A includes basic alphanumeric characters and ASCII Control Characters;
  • Set B includes basic alphanumeric characters and symbols;
  • Set C is a compressed representation of numbers where each character represents a double-digit number from 00 to 99.

Most applications use Set B or Set C (for numeric-only barcodes). Code 128 allows mixing of the three different sets in a single bar code via special control symbols. Code 128 also has several special barcode characters which provide special functionality, or are defined for use by certain subset standards. The Code 128 Table below shows the Code 128 character set.

All Code 128 barcodes begin with one of three start characters: Start A, Start B or Start C. All end with the standard Code 128 stop character. The Check Digit, if used, is placed directly before the stop character.

The following is a sample Code 128 barcode:

The sample barcode, with Check Digit, is composed of the following characters: <ALT + 0197>1287<ALT + 0199>

Code 128 Character Set

You'll notice in the table below that certain special characters are generated using ALT codes. To generate these in most programs you simply press ALT and enter the number following on the numeric keypad. The SPACE character is designated as ALT + 0207 because Microsoft Word and other word processors display a space character at the end of each line.

ValueFont Char Code Set ACode Set BCode Set B
0ALT + 0207 SPACE SPACE 00
1! ! ! 01
2" " " 02
3# # # 03
4$ $ $ 04
5% % % 05
6& & & 06
7' ' ' 07
8( ( ( 08
9) ) ) 09
10* * * 10
11+ + + 11
12, , , 12
13- - - 13
14. . . 14
15/ / / 15
160 0 0 16
171 1 1 17
182 2 2 18
193 3 3 19
204 4 4 20
215 5 5 21
226 6 6 22
237 7 7 23
248 8 8 24
259 9 9 25
26: : : 26
27; ; ; 27
28< < < 28
29= = = 29
30> > > 30
31? ? ? 31
32@ @ @ 32
33A A A 33
34B B B 34
35C C C 35
36D D D 36
37E E E 37
38F F F 38
39G G G 39
40H H H 40
41I I I 41
42J J J 42
43K K K 43
44L L L 44
45M M M 45
46N N N 46
47O O O 47
48P P P 48
49Q Q Q 49
50R R R 50
51S S S 51
52T T T 52
53U U U 53
54V V V 54
55W W W 55
56X X X 56
57Y Y Y 57
58Z Z Z 58
59[ [ [ 59
60\ \ \ 60
61] ] ] 61
62^ ^ ^ 62
63_ _ _ 63
64` NUL ` 64
65a SOH a 65
66b STX b 66
67c ETX c 67
68d EOT d 68
69e ENQ e 69
70f ACK f 70
71g BEL g 71
72h BS h 72
73i HT i 73
74j LF j 74
75k VT k 75
76l FF I 76
77m CR m 77
78n SO n 78
79o SI o 79
80p DLE p 80
81q DC1 q 81
82r DC2 r 82
83s DC3 s 83
84t DC4 t 84
85u NAK u 85
86v SYN v 86
87w ETB w 87
88x CAN x 88
89yEM y 89
90z SUB z 90
91{ ESC { 91
92| FS | 92
93} GS } 93
94~ RS ~ 94
95ALT + 0195 US DEL 95
96ALT + 0201 FNC 3 FNC 3 96
97ALT + 0202 FNC 2 FNC 2 97
98ALT + 0200 SHIFT SHIFT 98
99ALT + 0203 CODE C CODE C 99
100ALT + 0204 CODE B FNC 4 CODE B
101ALT + 0205 FNC 4 CODE A CODE A
102ALT + 0206 FNC 1 FNC 1 FNC 1
103ALT + 0196 Start A Start A Start A
104ALT + 0197 Start B Start B Start B
105ALT + 0198 Start C Start C Start C
106ALT + 0199 Stop Stop Stop

Code 128 Check Digits

Code 128 uses a "Weighted Mod 103" Check Digit. Here's how it's calculated:

  1. Multiply the assigned values of each character in the barcode by its position in the barcode and add them all together;
  2. Add the start character value to your total;
  3. Divide by 103. The remainder is your check digit value. You can look up the check digit character by its value in the Code 128 character table.

The Toolkit: True Type Fonts

There are two True Type Fonts included: Code39.ttf and Code128.ttf. To install the fonts, just copy them to your Windows\Fonts directory. These fonts have been tested with Microsoft Word and Microsoft Excel at various sizes, with a Zebex ZB-2200K CCD Barcode scanner and an HP LaserJet 6L laser printer. With this configuration, best results were obtained at font sizes of 14 points and higher.

The Toolkit: .NET Barcode Generator

A sample Barcode Generator program, written in VB.NET, has been included. The barcode generator program demonstrates how to perform the following tasks:

  • Generate Check Digits
  • Append start and stop symbols to barcodes
  • Generate a graphical barcode on a Windows Form using the included True Type fonts
  • Copy the barcode to the clipboard or save it as a bitmap file
  • Generate a properly encoded barcode string

The Barcode generator only accepts standard ASCII printable characters as input. Code 128 Set A special characters and other characters are not allowed as input. To install the program, just extract and run the .EXE file. To use the program, enter the text you wish to barcode, select a symbology (Code 39, Ext. Code 39 or Code 128), and press Generate. Once your barcode is displayed onscreen you can copy it to the clipboard by pressing Copy. You can also copy the encoded text from the Barcoded Text box and paste it into a Word document. You can then use the True Type fonts to display them as barcodes. Additionally you can save the barcode image as a bitmap file by selecting File > Save As File from the main menu.

Conclusion

Download the Barcode Toolkit

This set of tools is designed to make barcoding easier for developers. Barcoding is tied closely with modern database design and implementations. Whether you are using a database for inventory management, EDI, records management or other functions, using barcodes to help manage your data can make life easier.

Further Information

There is a wealth of information on barcoding around the Internet. Many sites are simply commercial sites that offer the bare minimum information to convince developers and managers to buy their products. One site that is very informative is Barcode Island (http://www.barcodeisland.com/).

If you have specific requirements, such as barcoding for EDI, you might want to visit ANSI to get information on their X.12 ASN 856 standard (http://www.ansi.org/). Additionally, you might need to visit an organizational subset to get specific implementation details, such as VICS for the retail industry (http://www.vics.org/home) or BISAC for book industry supply chain management (http://www.bisg.org/bisac/).

Rate

5 (1)

You rated this post out of 5. Change rating

Share

Share

Rate

5 (1)

You rated this post out of 5. Change rating