Barcodes are everywhere. From produce at the super market to tattoo’s on peoples necks. At first glance every barcode looks the same. However, in reality there are many different types of codes that encode data in different ways. Barcode software is able to detect what type of encoding the barcode is using by looking at the layout of the blocks in the code. This in and of itself is a fascinating feat. However, the more fascinating thing is that a seemingly random set of blocks actual can encode some pretty interesting information.
The most common form of barcode is the linear barcode. This is a simple identification (much like a license plate). A common misconception people have is that this image somehow has more information in it than it actually does. For example you go into the library and they scan the back of your library card (that has a linear barcode on it). After doing so the clerk is able to tell you your name, your address, how much you owe in late fees, and maybe even your credit card. None of this information is actually stored on your card. Rather what is scored on your card is just a unique number (sometimes with alpha characters as well). That number is read by whatever barcode software they are running and then fed into their database which has it associated with all the before mentioned information.
This makes sense if you think about it. The barcode doesn’t change each time you bring it in. Its not like they erase the ink off the back of your card and then re-apply it. Rather they use it in the same way that your social security number is used to identify you. Each time you check out a book that use your id off of the barcode on your card to mark that the book is checked out to you in their database. If you don’t get it back in time they start keeping track of your total fines. Next time you come back in and swipe your card they are able to read that id off of of the barcode using their software. This is what actually tells them the total to charge you.
This same principal is used at the supermarket. Each item has a unique ID encoded into a barcode. When the cashier rings up the item the price is not actually on the item. Instead the unique code is read off the thing being purchased. This code is then looked up in the price database and from their the program displays the price for the item being purchased.
The two most common formats for linear bar codes are either UPC or EAN. In reality there are over 300 different types of barcodes, but most of them are rarely used. The actual value of a barcode is read by either scanning a laser across them or capturing an image of them. In either case how thick the bars are, where they are located, and how much white space is between them allows the computer program to determine what the represented number or letter is.
Visual basic makes almost any programming task easy. However, out of the box it doesn't ship with any software that can read barcodes. The attached source code below remedies this by providing a module you can use to read a barcode image and get the value.
If you open the basBCREAD module you will see a comment describing who wrote this module and how you can call into it. The main Function we will call to read a barcode is bcRead.
bcRead has the following parameters:
|pb||The PictureBox that has a our barcode in it. Note that the picture box must have a picture in it that is monochrome (black and white only) and it should have the ScaleMode set to pixels|
|rX and rY||The location in the picture box that we should start read the barcode at.|
The type of barcode we will be reading (you can use the bcTypes Enum). This module supports these 3 types of codes:
Once you download the sample barcode software you can run it to see how the barcodes are read. Simply place your mouse where the red dot is on the picture below and click the left mouse button. You will see the result 7005099 show up in the result text box (in the upper left corner of the screen). Its as simple as that. Place your mouse in front of any of the other barcodes and you will be able to see the results for them as well. Note, however, that the other barcodes are in a different format. You will need to select the different format in the Barcode Type list (at the top of the screen).
You can also try your own barcodes in this software. Simply grab a picture of a barcode in windows explorer and drag it over the screen where the barcodes are currently. Your picture will replace those ones and you can once again click beside the barcode to read it. Make sure you select the correct encoding in the list though.
This is just the beginning. Feel free to build on this program by storing the id’s off the barcodes in a database along with other pertinent information. This makes it easy to create your own pricing program, inventory system, user id card program, etc. The possibilities are endless. If you are looking for ways to print some barcodes that you can use with this barcode software, I suggest this Free Barcode Generator.
Note: The author of this source code sample is Paul Bahlawan (you can read his information at the top of each code file).