Click here to Skip to main content
15,886,611 members
Articles / Programming Languages / C#

Format UPC-A Barcodes Using a .NET assembly

Rate me:
Please Sign up or sign in to vote.
5.00/5 (2 votes)
17 May 2009CPOL3 min read 29K   625   9   2
The attached assembly, used with the associated font, allows a developer to format UPC-A barcodes from any .NET project in a just a few lines of code.

Introduction

The attached assembly, used with the associated font, allows a developer to format UPC-A barcodes from any .NET project in just a few lines of code, as demonstrated here.

Highly skippable backgrounder

The Universal Product Code (UPC) specifications include three versions: A, D, and E. Version A, the regular version, is used to encode a twelve digit number. Version E, the zero suppressed version, is a six digit code used for marking small packages. Version D, the variable length version, is not commonly used for package marking. It is used in limited special applications.

Both Version A and E may include either a 2 digit or a 5 digit supplemental encoding. These extra digits are primarily used on periodicals and books. Supplemental encodings are supported.

Version A encodes a twelve digit number. The first number encoded is the number system character, the next ten digits are the data characters, and the last digit is the check character.

The number system character is printed in human readable form to the left of the UPC symbol. Seven of the ten possible numbers have been assigned.

UPC Number System Characters

CharacterUsage
0Regular UPC codes
1Reserved
2Random weight items which are symbol marked at the store level
3National Drug Code and National Health related Items Code
4For use without code format restrictions and with check digit protection for in-store marking of non-food items.
5For use on coupons
6Regular UPC codes
7Regular UPC codes
8Reserved
9Reserved

These number system characters are accessible as the UPCA.NumberSystem property of the UPCA object in the assembly.

Assembly Usage

In order to use the assembly and format UPC-A barcodes, download the attached zip files, unzip them, and follow the steps outlined below:

  1. First ensure that the UPCA font is installed on the target system
    1. Navigate to Control Panel and click on it to open.
    2. Double click fonts in Control Panel to open the Fonts Control Panel applet.
    3. Either drag the UPCA font into the fonts cache (the Fonts Control Panel applet) or click File->Install new font… navigate to the UPCA font, and select it.
  2. Add the UPCA assembly to your project in the following manner:
    1. Copy the assembly to your project folder.
    2. Add a reference to the assembly in your project.
    3. Image 1

    4. Add the using clause as below:
    5. C#
      using ako.UPC_A;
  3. You can now construct a UPCA object and call its methods in the following manner (also see the attached example project).
    1. Construct a UPCA object with a number system and barcode data (assuming the rich text box font is set to the UPCA font).
    2. C#
      richTextBox1.Text = new UPCA(number_system, textBox1.Text).upca;

      or…

    3. Construct a UPCA object, then set the NumberSystem and Data properties (assuming the rich text box font is set to the UPCA font).
    4. C#
      UPCA upc = new UPCA();
      upc.NumberSystem = "4";
      upc.Data = textBox1.Text;
      richTextBox1.Text = upc.upca;
    5. Obtain the formatted barcode from the UPCA property of the UPCA object e.g. (if declared as in (ii.) above):
    6. C#
      richTextBox1.Text = upc.upca;

Notes

  1. The UPCA object is declared as a partial class, allowing a user to extend its functionality as required (reference .NET partial classes). The actual declaration is shown below:
  2. C#
    public partial class UPCA : System.Object
  3. The read only UPCA.upca property is formatted to include all the data required for a properly formatted UPC-A barcode, including leading and trailing barcode stop characters, distinct left and right barcode characters, and the middle barcode characters.
  4. The UPCA font is free for personal, non-commercial use, but requires licensing for commercial use. If you require the font for commercial purposes, please contact me (agolakisira@gmail.com) for details.

History

First version and first article; any and all comments appreciated.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Questionbarcode in code 39 Pin
Member 79252208-Jul-11 22:30
Member 79252208-Jul-11 22:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.