Thanks Larry,

I did a poor job stating my request.  

I am aware of the formula to create the check character. What I meant to ask
is if there is any built in code in R:Base that can be triggered to
calculate the check character.

My thoughts were triggered by the fact that the report generator has the
capability to calculate the check character.  I thought that maybe there was
an undocumented function that would handle the calculation.

BTW... the multiplier for the sum of the odd digits should be 3.

John 

-----Original Message-----
From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Lawrence
Lustig
Sent: Wednesday, February 16, 2005 9:30 PM
To: RBG7-L Mailing List
Subject: [RBG7-L] - Re: UPC-A check digit

> Is there a way to have R:Base create the check character when you enter
the
> first 11 digits so that I can store the full 12 digit code? 
> Since R:Base will create the check character when you print a UPC barcode,
I
> suspect that there is a way to do this.  

The check digit printed on the bar code is calculated as part of the bar
code
component -- I don't know anyway to get to it from R:Base code.

However, this page gives the calculation formula for the check digit:
http://www.export911.com/e911/coding/upcChar.htm (the check digit is
discussed
at the end of the page).

Briefly, if vUPCCode contains the 11 digit code:

SET VAR vOddSum = (INT(SGET(.vUPCCode, 1, 1))) + +
                  (INT(SGET(.vUPCCode, 1, 3))) + +
                  (INT(SGET(.vUPCCode, 1, 5))) + +
                  (INT(SGET(.vUPCCode, 1, 7))) + +
                  (INT(SGET(.vUPCCode, 1, 9))) + +
                  (INT(SGET(.vUPCCode, 1, 11)))

SET VAR vEvenSum = (INT(SGET(.vUPCCode, 1, 2))) + +
                  (INT(SGET(.vUPCCode, 1, 4))) + +
                  (INT(SGET(.vUPCCode, 1, 6))) + +
                  (INT(SGET(.vUPCCode, 1, 8))) + +
                  (INT(SGET(.vUPCCode, 1, 10)))

SET VAR vUPCTotal = ((.vOddSum * 2) + .vEvenSum)

SET VAR vUPCCheckDigit = (10 - MOD(.vUPCTotal, 10))

SET VAR vNewUPDCode = (.vUPCCode + CTXT(.vUPCCheckDigit))

I put the formula (untested, by the way!) into four separate expressions for
the sake of clarity, but you could easily crunch it into a single formula
and
use it to define a computed column in the table if you want.

Depending on the application, you may find it more efficient to code this up
as
a C or Delphi language UDF and use it that way.  
--
Larry

Reply via email to