Manual Encode 128

By default Barcode.AutoEncode is set to true. For most applications, you should use the AutoEncode feature – which creates the encoded version of the data automatically.

Set AutoEncode to False and manually encode the data for a Code 128 BarCode when you have special requirements.

If you are unfamiliar with Code 128, I will try to give you a quick tutorial, as Code 128 is more complicated than most other one-dimensional barcodes.

The first thing you must know about Code 128 is that it has three different character sets (A, B, and C).  That means one set of bars can mean three different things based on which set is currently in use.  The other tricky bit is that you have the option of switching character sets in the middle of the code.  I think you see now why this is a more difficult code.

Character set A can encode most symbol characters (!,$,/, etc.) as well as all uppercase letters and the ten digits.  In addition, it can encode the “special” ASCII characters, such as carriage return, line feed, null, escape, etc.

Character set B encodes all symbol characters, upper and lowercase letters and the ten digits.

Character set C encodes 100 pairs of numbers.  That is, one set of bars could mean “05” or “43”, etc.  This effectively doubles the density of Code 128 when using numbers only.  Also note, because they are numeric pairs, the Code C portion must have an even number of digits.

Now that you know what the differences in the codes are, you now have to know how to use them with the BarCode component.  Since all normal ASCII characters are used by Code 128, we must use special characters to tell the component what to do.  The BarCode component uses ASCII values Char(208) through Char(242) for this purpose.  If you’re using the Object Inspector to type the Data property, you hold down the Alt key, then type (on the numeric keypad) 0 + the number  (Alt-0208 for instance).  The table below lists all of the special characters.

Char(208)  START A
Char(209)  START B
Char(210)  START C

 

 

 

These are the special START CODE characters.  Each Code 128 barcodes MUST START with one of the three above. Which start code you use is   obviously which character set is active.  You cannot use a start code in the middle of a symbol.  See the table below for the special codes used to     switch to a different character set.

 

 Special Char  Character Set A  Character Set B  Character Set C
Char(201)  Function 3  Function 3  <none>
Char(202)  Function 2  Function 2  <none>
Char(203)  TempShift to B  TempShift to A  <none>
Char(204)  Switch to C  Switch to C  <none>
Char(205)  Switch to B  Function 4  <none>
Char(206)  Function 4  Switch to A  Switch to A
Char(207)  Function 1  Function 1  Function 1
Char(211)  NUL  <none>  <none>
Char(212)  SOH  <none>  <none>
Char(213)  STX  <none>  <none>
Char(214)  ETX  <none>  <none>
Char(215)  EOT  <none>  <none>
Char(216)  ENQ  <none>  <none>
Char(217)  ACK  <none>  <none>
Char(218)  BEL  <none>  <none>
Char(219)  BS  <none>  <none>
Char(220)  HT  <none>  <none>
Char(221)  LF  <none>  <none>
Char(222)  VT  <none>  <none>
Char(223)  FF  <none>  <none>
Char(224)  CR  <none>  <none>
Char(225)  SO  <none>  <none>
Char(226)  SI  <none>  <none>
Char(227)  DLE  <none>  <none>
Char(228)  DC1  <none>  <none>
Char(229)  DC2  <none>  <none>
Char(230)  DC3  <none>  <none>
Char(231)  DC4  <none>  <none>
Char(232)  NAK  <none>  <none>
Char(233)  SYN  <none>  <none>
Char(234)  ETB  <none>  <none>
Char(235)  CAN  <none>  <none>
Char(236)  EM  <none>  <none>
Char(237)  SUB  <none>  <none>
Char(238)  ESC  <none>  <none>
Char(239)  FS  <none>  <none>
Char(240)  GS  <none>  <none>
Char(241)  RS  <none>  <none>
Char(242)  US  <none>  <none>

Got all that?  <smile>  Ok, so here’s what that table means:  if the current character set is A, then a Char(205) means Switch to Code B.  If the current set was B, that same #205 means Function 4.

The Switch codes are all boldfaced because you’ll probably use those the most.  A Switch code means “Switch to Character Set X for the remainder of the code, or until another Switch code is encountered.”

The Temp-Shift codes means “Shift to Code X for the next character only.”

The “Function” codes mean different things based on your barcode reader.  Generally they are explained in the reader’s documentation.

Ok, I think a few examples are in order:

Let’s say you want to encode the text “CODE 128”.  Character set A is sufficient.  Here’s how:

  ppBarCode1.Data := Char(208) + 'CODE 128';

If you were using the Object Inspector, you would’ve typed {Alt-0208}CODE 128.

Here’s a little more advanced example.  We want to encode “1234 abcd”.  We can use Set C, since we have an even number of digits.  Then we have to switch to Set B for the lowercase letters.

  ppBarCode1.Data := Char(210) + '1234' + Char(205) + ' abcd';

Ok, one last example.  We want to encode “Soft Sector 1996”, but we want a Carriage Return in between “Soft” and “Sector”.  Here goes:

  ppBarCode1.Data := Char(209) + 'Soft' + Char(203) +  Char(224) + 'Sector ' + Char(204) + '1996';

See what happened there?  We started off in Set B and wrote “Soft”, then we Temp Shifted to A to encode the CR.  The we wrote “Sector” in Set B.  Finally, we switched to Set C to encode “1996.”