# calculate the EAN ( barcode) check digit

ever made a program capable of showing barcodes ?
if you did than you`ve been there ,,, at the oficial EAN standards site,, than you would have seen how to calculate the check digit.
they hold the standard they publish that standard also on their website ,,,
http://www.ean-int.org/index800.html
i never found code in VB that calculates the check digit ,, so my conclusion is that it was hold for comercial reassons ( there are lots of controls out there for a lot of monney :-)
so i donate this M. Posseth code to the public and make it public domain ,,,
uhmmm votes would be apreciated :-)

Original Author: Michel Posseth

### Inputs

13 digit EAN code ( manufacterer number , parts number )

### Returns

14 digit EAN code ( calculates the check digit )

### Code

`Private Function CalcEanMetcontrole(ByVal EAN13Digit As String) As StringDim Explodestring As StringDim DigArrayDim Digit As VariantDim factor As IntegerDim Standin As IntegerDim som As IntegerDim CG As IntegerExplodestring = Left\$(Replace(StrConv(EAN13Digit, vbUnicode), vbNullChar, _        ","), Len(EAN13Digit) * 2 - 1)  DigArray = Split(Explodestring, ",", -1, 1)factor = 3For Each Digit In DigArrayStandin = CInt(Digit)som = som + (Standin * factor)factor = 4 - factorNextIf Right\$(CStr(som), 1) = 0 ThenCG = 0ElseCG = 10 - Right\$(som, 1)End IfCalcEanMetcontrole = Trim\$(EAN13Digit & CStr(CG))End Function`

Posted: 2002-06-01
By: ArchiveBot
Viewed: 96 times

Categories

Visual Basic 6

Attachments

No attachments for this post