Dynamically Generating I25 Bar CodesBy Daniel Goncalves
|More Bar Chart Articles!|
|To learn more about dynamically generating Code 39 bar charts through an ASP page, be sure to read: Generating Dynamic Code 39 Bar Code on a Web Page!|
This article demonstrates how to generate a barcode I25 (interleaved 2-of-5) using server-side VBScript
without using a database. First, I've assumed that you don't know what is I25 and how it's encoded.
Interleaved 2-of-5 Specifications
I25 is a barcode that can encode numbers only. We have ten patterns, each one represents a single digit (0 to 9) in our decimal numeric scheme. The following picture shows these patterns.
The I25 specification says that each symbol must be interleaved with another. Thus, a pair of digits can be represented by only one I25 unit. As showed in the figure below, the first digit is encoded in the bars and the second interleaved as spaces. Note that 2-of-5 becames from the fact that in a I25 unit there are five bars, two of which are wide and five spaces, two of which are wide.
The symbol in the figure cannot be read because is incomplete. A complete barcode I25 must have a leading quiet zone (usualy at least .25" of width), a start symbol, the number you wish enconded, the stop symbol and a trailing quiet zone. Also note that since the digits are interleaved, there must be an EVEN number of digits in the bar code. A bar code of "11" is legal I25 code, but a bar code of "111" is not.
How To Encode A Number To I25 Pattern
With this knowledge, you're ready to let me guide you to creating a VBScript function that will generate these barcodes. First we'll create a function called
I25Encode(). This function will receive a single
argument as a string that is the number we wish to encode and interleave.
To do that, we'll create an array with 10
elements. Each element will contain the pattern for a specific digit. (If you are interested in seeing the
results, go ahead and give the live demo a whirl!)
Now we'll perform some validations to the received argument. Note that the number of characters in the argument must be even; all characters in the argument must be between 0 and 9 (48 to 57 according to the ASCII table). Then:
Ok! The validation is done. (The routine is more efficient if the validation section will placed between the
Dim and the
Redim statements. Do that If you want.) Now we must read the characters
in the received argument to encode and interleave them with the following code:
Well done! We already got the encoded and interleaved result. Just add the start and stop patterns and return them.
Now we must read the returned encoded data and generate the barcode. We'll look at accomplishing this in Part 2!