View Full Version : Excel Scanline Check Digit

rsheldon

October 20th, 2014, 10:54 AM

Good Afternoon Everyone,

I am not sure that this is the correct forum to be on, but I will ask anyway. I am using VDP 9.1 in Acrobat 10.1 on iOS 10.8.5. I have a client that has sent in a database that I need to create a Scanline using 2 fields. The data is alphanumeric, and I need to create a Check Digit using a Mod10 with weights of 2, 1, 2, 1. Sample data is:

Field 1 Field 2

CON135627 U14B1DDBMR

The result is 0CON135627 U14B1DDBMR8, with 8 being the check digit.

I am so confused :eek:

Dan Korn

October 20th, 2014, 12:27 PM

What do you mean by a "scanline?" Are you trying to output a bar code? Or do you just literally want a string of numbers and letters like "0CON135627 U14B1DDBMR8" to be in the output?

rsheldon

October 20th, 2014, 12:37 PM

Good Afternoon Dan,

The Scanline is an alphanumeric string of text like the sample I gave. It uses the font OCR A. So yes, just a string of text, no barcode. I have received a few scanlines from other clients, but they come in already formatted in excel. Unfortunately with this one, I am creating from 2 fields in the database. The instructions I received are in the attached .xls file

Dan Korn

October 20th, 2014, 04:40 PM

Good Afternoon Dan,

The Scanline is an alphanumeric string of text like the sample I gave. It uses the font OCR A. So yes, just a string of text, no barcode. I have received a few scanlines from other clients, but they come in already formatted in excel. Unfortunately with this one, I am creating from 2 fields in the database. The instructions I received are in the attached .xls file

Okay, out of everything in that Zip file, the instructions about this check digit are really just this one line from the Excel file: "This is the scan-line check digit - Modulus 10, double add double, sum of the digits,with weights of 2121,etc from right to left." I asked my best expert about this; his name is Dr. Google. Pasting that text into Google returns this:

https://www.claredi.com/download/npi_luhn.html

So I think that's the formula. But that formula is specific to numbers. It doesn't say what to do with non-digits, i.e letters. How are you supposed to get the "sum" of "CON135627 U14B1DDBMR"? Are you supposed to add the ASCII values of the letters, like for a POSTNET barcode?

Once we have some numbers to deal with, it should be easy enough to apply the formula in that link. But what do we do with the letters?

Maybe what we really need is this:

http://en.wikipedia.org/wiki/CUSIP#Check_digit_pseudocode

But, as much fun as it is for me to do all of this research for you, I think you need to get some clarification from whoever sent you those instructions about exactly what it means to make a check sum of "Modulus 10, double add double, sum of the digits" with something other than digits.

rsheldon

October 22nd, 2014, 03:26 AM

Thanks Dan for taking a look at this for me. I have reached out to a caging house as well. This is where they check the scanline. I figured if they couldn't tell me, I am in deep deep trouble. From what I was reading in the scanline instructions: A = 3o, B = 31, C = 32 all the way to Z = 55, but I am still lost.

step

October 22nd, 2014, 08:10 AM

I set this up using the formula Dan posted (https://www.claredi.com/download/npi_luhn.html) (or at least I tried to). The check digit, as I determined it, doesn't match your example so I'm not sure this is going to help you at all but I figured it may at least give you a starting place or at the very least the function for converting the alpha characters to the numeric values you listed above. I'm also unsure of where the leading zero is coming from in your example from your original post so that may have something to do with why my solution is a bit off.

// Initiate variables

var field1 = "CON135627";

var field2 = "U14B1DDBMR";

var result = [];

var checkDigit = 0;

// Function to convert alphas:

// A = 30

// B = 31

// Z = 55

function getAlpha(input){

var alpha = ['a','b','c','d','e','f','g','h','i','j','k','l','m ','n','o','p','q','r','s','t','u','v','w','x','y', 'z'];

var result = alpha.indexOf(input);

return result + 30;

}

// Concatenate fields to create the barcode field

var barcode = field1 + field2;

// Replace alphas with numbers

barcode = barcode.replace(/[a-z]/gi, function(s){return getAlpha(ToLower(s));});

// For loop to double every other number

for (var i=0; i<barcode.length; i++) {

if (i%2 == 1) {

result.push(barcode[i]*2);

}

else {

result.push(barcode[i]);

}

}

// Join result of the above for loop into a string of numbers to be added together

result = result.join('');

// For loop to all of the numbers together

for (var n=0; n<result.length; n++){

checkDigit += Int(result[n]);

}

// Modulus 10

checkDigit = 10-(checkDigit%10);

return field1 + " " + field2 + checkDigit;

vBulletin® v3.8.4, Copyright ©2000-2019, Jelsoft Enterprises Ltd.