EAN-13 Check Digit Calculator

In case anyone is interested, here is the function I created to calculate the EAN-13 check digit, I know it could be written much cleaner :wink:

[code]function GetEAN13CheckDigit(barcode as String) as Integer
if len(barcode)<>12 then
return -1
else
dim result as integer = 0
dim calc as integer = 0
dim n as integer = 0
dim roundedResult as integer = 0

for lp as integer = 1 to 12
  if (lp mod 2)=0 then
    calc = val(mid(barcode, lp, 1)) * 3
  else
    calc = val(mid(barcode, lp, 1)) * 1
  end if
  result = result + calc
next

roundedResult = Ceil(result/10)*10

return roundedResult - result

end if
end function[/code]