Barcodes in LBI

I’ve been getting hits lately for “barcodes in LBI”, so I thought I’d mention how we do barcodes in LBI. When I say LBI, I’m really just talking about Reporting Services and how to do barcodes in the context of Crystal Reports.

The most important thing to consider is what format your reports are going to be delivered in. There are two choices: PDF and any other file format (including crystal). When delivering the report in PDF format, it is not necessary for the report user to have any special setup or configurations. Any other format would probably require special setup. I say “probably” because I’m not certain. The only method I’m aware of to generate barcodes in Crystal is by using a barcode font. This means that for any delivery format besides PDF, the end user must have the barcode font installed on their local machine. However, there is a way to use CSS in Crystal reports, so it’s entirely possible that you may be able to generate a barcode that way, like I discuss here, but I’ve never tried it using it like that.

We currently use two different types of barcodes: Code39 and Code128. The Code39 barcode is from Azalea and the Code128 is from Dobson software.

Despite what the Azalea site says, Code39 does not require check digits. Many scanners also don’t require that you put the leading and trailing * characters (at least the three different brands of scanners that we have do not require them). This means that you can just use the Azalea font for the Crystal field and that’s it. I honestly can’t say whether we paid for Code39 or not as I’m not the one who implemented it’s use. For more on Code39, see the Wikipedia page.

Code128, on the other hand, is fairly complicated. It has three different flavors (A,B,C) and requires different characteristics depending on the type. Using this font in Crystal requires that you use a formula (or UFL) to properly generate the barcode. See the Wikipedia page for more info on Code128. The formula I use to generate correct Code128 is below.

(Note: this code generates a Code128B and uses the Code128bWin font from Dobson Software. This particular code happens to also be from one of the reports – W4 – that is part of our new hire onboarding application. It is generated from LBI and the barcode is read in ImageNow where it’s linked and filed automatically by Recognition Agent.)

Local StringVar strText := "Payroll_Employee" & "^" & {xml.ssn} & "^" {xml.EMPLOYEE_ID} & "^" & {xml.last_name} & "^" & {xml.first_name} & "^PR_Federal_W4";
//Replacing spaces in text string.  For some reason the barcode is unreadable when I leave them in
strText := Replace (strText, " ", "+");
Local NumberVar intRunTotal := 104;  //Start code for Bset of Code128
Local NumberVar intLength := Length(strText);
Local Numbervar i;
Local Numbervar intCodeValue;   //Code128 value of current character
Local Numbervar intCheckValue;  //Check value in Code128
Local NumberVar intCheckValueA;  //Hold ASCII value for Code128 value

for i:= 1 to intLength Do
(
    Local StringVar strChar := strText[i];
    //Get code128 value
    If ASC(strChar) = 128 Then
        intCodeValue := 0
    Else 
    (
        If ASC(strChar) >= 33 And ASC(strChar) = 1 And intCheckValue <= 94 Then
        	intCheckValueA := intCheckValue + 32
    	Else
        	intCheckValueA := intCheckValue + 50
    );

    //Add to running total for check char
    intRunTotal := intRunTotal + (intCodeValue * i)
);

//Get check value which is remainder of running total / 103
intCheckValue := intRunTotal Mod 103;

//Convert back to ASCII to display
If intCheckValue = 0 then
    intCheckValueA := 128
Else
(
    If intCheckValue >= 1 And intCheckValue <= 94 Then
        intCheckValueA := intCheckValue + 32
    Else
        intCheckValueA := intCheckValue + 50
);
strText := chr(154) & strText & chr(intCheckValueA) & chr(156)

HTH

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s