UPC bar code check digit calcuation

UPC Barcode Check Digits

UPC barcodes include a check digit. The UPC check digit is the 12th digit in the lower-right corner of the barcode. Here's how to calculate a UPC barcode check digit

The last digit in a UPC barcode is a check digit based on the previous 11 numbers. Our example barcode data is "41234554321"

Add up the numbers in the odd positions left to right. Multiple the result by 3. Add up the numbers in the even positions. Now add the first subtotal to the second. The UPC barcode check digit is the single digit number makes the total a multiple of 10

4+2+4+5+3+1=19 19x3=57 1+3+5+4+2=15 57+15=72 and 8 makes 80

In VBA/Visual Basic it looks something like this:

Function AzaleaUPCcheckdigit(ByVal yourInput as String) as String
' Copyright 2006 Azalea Software, Inc. All rights reserved. www.azalea.com
' The input, yourInput, is your 11-digit company prefix + product number

Dim checkDigitSubtotal As Integer ' temporary variable during the calculation

checkDigitSubtotal = 3 * (Val(Left$(yourInput, 1) + Val(Mid$(yourInput, 3, 1)) + Val(Mid$(yourInput, 5, 1)) + Val(Mid$(yourInput, 7, 1)) + Val(Mid$(yourInput, 9, 1)) + Val(Right$(yourInput, 1)))
checkDigitSubtotal = checkDigitSubtotal + Val(Mid$(yourInput, 2, 1)) + Val(Mid$(yourInput, 4, 1)) + Val(Mid$(yourInput, 6, 1)) + Val(Mid$(yourInput, 8, 1)) + Val(Mid$(yourInput, 10, 1))
AzaleaUPCcheckdigit = Right$(Str$(300 - checkDigitSubtotal), 1)

End Function

The wizard utility in UPCTools calculates the check digit for you. All of the free sample code for UPCTools does it too.