> 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