Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: How to calculate EAN-13 barcode check digit



Permlink Replies: 17 - Last Post: Nov 24, 2014 8:17 AM Last Post By: Ian Murphy
Andy Colmes

Posts: 93
Registered: 2/5/98
How to calculate EAN-13 barcode check digit
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 31, 2011 1:41 PM
I found this VB function but I couldn't find a Delphi one. I would
appreciate if anyone has a good function in Delphi or if not, help me
convert the following to Delphi.

Thanks in advance.

Andy

CREATE FUNCTION fu_EAN13CheckDigit (@Barcode
-->>>><&lt;&gt;<<<<&lt;&gt;>>>>>>>>>>>>>>>< <><><>
RETURNS varchar(13)
AS
BEGIN
DECLARE @SUM int ,
@COUNTER int,
@RETURN varchar(13),
@Val1 int,
@Val2 int
SET @COUNTER = 1
SET @SUM = 0
WHILE @Counter < 13
BEGIN
SET @VAL1 = SUBSTRING(@Barcode,@counter,1) * 1
SET @VAL2 = SUBSTRING(@Barcode,@counter + 1,1) * 3
SET @SUM = @VAL1 + @SUM
SET @SUM = @VAL2 + @SUM
SET @Counter = @Counter + 2
END
SET @Counter = ROUND(@SUM + 5,-1)
SET @Return = @BARCODE + CONVERT(varchar,((@Counter - @SUM)))
RETURN @Return
END
Jeffrey Ottery

Posts: 42
Registered: 11/27/05
Re: How to calculate EAN-13 barcode check digit
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 31, 2011 5:37 PM   in response to: Andy Colmes in response to: Andy Colmes
It's a mod 10 check digit.

function GetMod10CheckDigit(Number: String): Integer;
var SLen,CurrentPos,Total1,Total2,Total3,Count: Integer;
TempStr: String;
begin
Slen:=Length(Number);
CurrentPos:=SLen;
Total1:=0;Total2:=0;
while (1=1) do
begin
Total1:=Total1+strtointdef(Number[CurrentPos],0);
CurrentPos:=CurrentPos-2;
if CurrentPos<1 then break;
end;

CurrentPos:=SLen-1;
while (1=1) do
begin
Total2:=Total2+strtointdef(Number[CurrentPos],0);
CurrentPos:=CurrentPos-2;
if CurrentPos<1 then break;
end;
Total3:=(3*Total1)+Total2-1;
for Count:=0 to 9 do
begin
inc(Total3);
TempStr:=inttostr(Total3);
if copy(TempStr,Length(TempStr),1)='0' then
begin
Result:=Count;
exit;
end
end;
Result:=0;
end;

Andy Colmes

Posts: 93
Registered: 2/5/98
Re: How to calculate EAN-13 barcode check digit
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 1, 2011 3:13 AM   in response to: Jeffrey Ottery in response to: Jeffrey Ottery
Thanks Jeffrey for the help.

Andy

"Jeffrey Ottery" wrote in message news:415797 at forums dot embarcadero dot com...

It's a mod 10 check digit.

function GetMod10CheckDigit(Number: String): Integer;
var SLen,CurrentPos,Total1,Total2,Total3,Count: Integer;
TempStr: String;
begin
Slen:=Length(Number);
CurrentPos:=SLen;
Total1:=0;Total2:=0;
while (1=1) do
begin
Total1:=Total1+strtointdef(Number[CurrentPos],0);
CurrentPos:=CurrentPos-2;
if CurrentPos<1 then break;
end;

CurrentPos:=SLen-1;
while (1=1) do
begin
Total2:=Total2+strtointdef(Number[CurrentPos],0);
CurrentPos:=CurrentPos-2;
if CurrentPos<1 then break;
end;
Total3:=(3*Total1)+Total2-1;
for Count:=0 to 9 do
begin
inc(Total3);
TempStr:=inttostr(Total3);
if copy(TempStr,Length(TempStr),1)='0' then
begin
Result:=Count;
exit;
end
end;
Result:=0;
end;

Ian Murphy

Posts: 20
Registered: 2/25/00
Re: How to calculate EAN-13 barcode check digit
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 1, 2011 2:54 AM   in response to: Andy Colmes in response to: Andy Colmes
On Mon, 31 Oct 2011 13:41:56 -0700, Andy Colmes <andycolmes at yahoo dot com>
wrote:

Hi Andy,

Try this function:

Function GetCheckDigit(Barcode:String):String;
Var
I,SumOdd,SumEven,Tot:Integer;
begin
SumOdd := 0;
SumEven := 0;
For I := 1 to length(Barcode) do begin
if Odd(I) then SumOdd := SumOdd + StrToInt(Copy(Barcode,I,1))
else SumEven := SumEven + StrToInt(Copy(Barcode,I,1));
end;
Tot := ( (SumOdd*3) + SumEven );
if Tot mod 10 = 0 then Tot := 0 else Tot := 10 - (Tot mod 10);
Result := Trim(IntToStr(Tot));
end;

As you can see it's a mod 10 function

regards

Ian Murphy

I found this VB function but I couldn't find a Delphi one. I would
appreciate if anyone has a good function in Delphi or if not, help me
convert the following to Delphi.

Thanks in advance.

Andy

CREATE FUNCTION fu_EAN13CheckDigit (@Barcode
-->>>><&lt;&gt;<<<<&lt;&gt;>>>>>>>>>>>>>>>< &lt;&gt;&lt;&gt;&lt;&gt;
RETURNS varchar(13)
AS
BEGIN
DECLARE @SUM int ,
@COUNTER int,
@RETURN varchar(13),
@Val1 int,
@Val2 int
SET @COUNTER = 1
SET @SUM = 0
WHILE @Counter < 13
BEGIN
SET @VAL1 = SUBSTRING(@Barcode,@counter,1) * 1
SET @VAL2 = SUBSTRING(@Barcode,@counter + 1,1) * 3
SET @SUM = @VAL1 + @SUM
SET @SUM = @VAL2 + @SUM
SET @Counter = @Counter + 2
END
SET @Counter = ROUND(@SUM + 5,-1)
SET @Return = @BARCODE + CONVERT(varchar,((@Counter - @SUM)))
RETURN @Return
END
Andy Colmes

Posts: 93
Registered: 2/5/98
Re: How to calculate EAN-13 barcode check digit
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 1, 2011 3:12 AM   in response to: Ian Murphy in response to: Ian Murphy
Thank you Ian for the help.

Andy

"Ian Murphy" wrote in message news:415833 at forums dot embarcadero dot com...

On Mon, 31 Oct 2011 13:41:56 -0700, Andy Colmes <andycolmes at yahoo dot com>
wrote:

Hi Andy,

Try this function:

Function GetCheckDigit(Barcode:String):String;
Var
I,SumOdd,SumEven,Tot:Integer;
begin
SumOdd := 0;
SumEven := 0;
For I := 1 to length(Barcode) do begin
if Odd(I) then SumOdd := SumOdd + StrToInt(Copy(Barcode,I,1))
else SumEven := SumEven + StrToInt(Copy(Barcode,I,1));
end;
Tot := ( (SumOdd*3) + SumEven );
if Tot mod 10 = 0 then Tot := 0 else Tot := 10 - (Tot mod 10);
Result := Trim(IntToStr(Tot));
end;

As you can see it's a mod 10 function

regards

Ian Murphy

I found this VB function but I couldn't find a Delphi one. I would
appreciate if anyone has a good function in Delphi or if not, help me
convert the following to Delphi.

Thanks in advance.

Andy

CREATE FUNCTION fu_EAN13CheckDigit (@Barcode
-->>>><&lt;&gt;<<<<&lt;&gt;>>>>>>>>>>>>>>>< &lt;&gt;&lt;&gt;&lt;&gt;
RETURNS varchar(13)
AS
BEGIN
DECLARE @SUM int ,
@COUNTER int,
@RETURN varchar(13),
@Val1 int,
@Val2 int
SET @COUNTER = 1
SET @SUM = 0
WHILE @Counter < 13
BEGIN
SET @VAL1 = SUBSTRING(@Barcode,@counter,1) * 1
SET @VAL2 = SUBSTRING(@Barcode,@counter + 1,1) * 3
SET @SUM = @VAL1 + @SUM
SET @SUM = @VAL2 + @SUM
SET @Counter = @Counter + 2
END
SET @Counter = ROUND(@SUM + 5,-1)
SET @Return = @BARCODE + CONVERT(varchar,((@Counter - @SUM)))
RETURN @Return
END
Dmitry Burov

Posts: 2
Registered: 3/20/04
Re: How to calculate EAN-13 barcode check digit
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 1, 2011 1:43 PM   in response to: Andy Colmes in response to: Andy Colmes
Andy Colmes <andycolmes at yahoo dot com> писал(а) в своём письме Tue, 01 Nov
2011 00:41:56 +0400:

I found this VB function but I couldn't find a Delphi one. I would

why not just take readymade barcode kits ?

http://www.torry.net/quicksearchd.php?String=barcode&Title=no

--
Написано в почтовом клиенте браузера Opera: http://www.opera.com/mail/
mark brown

Posts: 1
Registered: 3/11/12
Re: How to calculate EAN-13 barcode check digit
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 11, 2012 7:41 AM   in response to: Andy Colmes in response to: Andy Colmes
EAN13 Encoding Component in vb.net and Delphi with automatic check diit calculation.
Carter Anderson

Posts: 1
Registered: 5/26/13
Re: How to calculate EAN-13 barcode check digit
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 26, 2013 12:11 AM   in response to: mark brown in response to: mark brown
This EAN 13 barcode generator library for VB.NET also supports to calculate the check digit automatically. Here's its data encoding guide in VB.NET.

Edited by: Carter Anderson on Apr 26, 2013 12:12 AM
mariah sharp

Posts: 6
Registered: 9/12/13
Re: How to calculate EAN-13 barcode check digit
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 12, 2013 1:17 AM   in response to: Andy Colmes in response to: Andy Colmes
Andy Colmes wrote:
I found this VB function but I couldn't find a Delphi one. I would
appreciate if anyone has a good function in Delphi or if not, help me
convert the following to Delphi.

Thanks in advance.

Andy

CREATE FUNCTION fu_EAN13CheckDigit (@Barcode
-->>>><&lt;&gt;<<<<&lt;&gt;>>>>>>>>>>>>>>>< &lt;&gt;&lt;&gt;&lt;&gt;
RETURNS varchar(13)
AS
BEGIN
DECLARE @SUM int ,
@COUNTER int,
@RETURN varchar(13),
@Val1 int,
@Val2 int
SET @COUNTER = 1
SET @SUM = 0
WHILE @Counter < 13
BEGIN
SET @VAL1 = SUBSTRING(@Barcode,@counter,1) * 1
SET @VAL2 = SUBSTRING(@Barcode,@counter + 1,1) * 3
SET @SUM = @VAL1 + @SUM
SET @SUM = @VAL2 + @SUM
SET @Counter = @Counter + 2
END
SET @Counter = ROUND(@SUM + 5,-1)
SET @Return = @BARCODE + CONVERT(varchar,((@Counter - @SUM)))
RETURN @Return
END
isn't this thread about ean-13 barcode ?if yes,I want someone to share the ean-13 barcode generator for me, except this one

Edited by: mariah sharp on Aug 12, 2013 1:17 AM

Edited by: mariah sharp on Aug 12, 2013 1:18 AM
Ian Murphy

Posts: 20
Registered: 2/25/00
Re: How to calculate EAN-13 barcode check digit [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 19, 2013 2:56 AM   in response to: mariah sharp in response to: mariah sharp
On Mon, 12 Aug 2013 01:19:57 -0700, mariah sharp <> wrote:

This is the function I use:

Function GetModulo10(Test: String):String;
Var
Working: String;
xOdd,xEven,xSum,xAnswer:Integer;
I:Integer;

Function Reverse(S:String):String;
Var
I:Integer;
begin
Result := '';
For I := Length(S) downto 1 do begin
Result := Result + copy (S,I,1);
end;
end;

begin
// Reverse the string to make it easier
Working := Reverse(Test);
xOdd := 0;
xEven := 0;
For I := 1 to Length(Working) do begin
if Odd(I) then xOdd := xOdd + (StrToInt(Copy(Test,I,1)) * 3)
else xEven := xEven + StrToInt(Copy(Test,I,1));
end;
xSum := xOdd + xEven;
While xSum > 10 do xSum := xSum - 10;
xAnswer := 10 - xSum;
Result := IntToStr(xAnswer);
end;

The way I use if is to say something like:

Function CheckModulo10(Test: String):Boolean;
Var
T1,T2:String;
begin
T1 := GetModulo10(Copy(Test,1,Length(Test)-1));
T2 := Copy(Test,Length(Test),1);
Result := (T1 = T2);
// This could be streamlined to remove the vars, but meh!
end;

Regards

Smurf

Andy Colmes wrote:
I found this VB function but I couldn't find a Delphi one. I would
appreciate if anyone has a good function in Delphi or if not, help me
convert the following to Delphi.

Thanks in advance.

Andy

CREATE FUNCTION fu_EAN13CheckDigit (@Barcode
-->>>><&lt;&gt;<<<<&lt;&gt;>>>>>>>>>>>>>>>< &lt;&gt;&lt;&gt;&lt;&gt;
RETURNS varchar(13)
AS
BEGIN
DECLARE @SUM int ,
@COUNTER int,
@RETURN varchar(13),
@Val1 int,
@Val2 int
SET @COUNTER = 1
SET @SUM = 0
WHILE @Counter < 13
BEGIN
SET @VAL1 = SUBSTRING(@Barcode,@counter,1) * 1
SET @VAL2 = SUBSTRING(@Barcode,@counter + 1,1) * 3
SET @SUM = @VAL1 + @SUM
SET @SUM = @VAL2 + @SUM
SET @Counter = @Counter + 2
END
SET @Counter = ROUND(@SUM + 5,-1)
SET @Return = @BARCODE + CONVERT(varchar,((@Counter - @SUM)))
RETURN @Return
END
isn't this thread about ean-13 barcode ?if yes,I want someone to share the ean-13 barcode generator for me, except this one

Edited by: mariah sharp on Aug 12, 2013 1:17 AM

Edited by: mariah sharp on Aug 12, 2013 1:18 AM
--
Ian Murphy Work: imurphy at datadialogue dot co dot uk
Systems Manager
************************************************************************************
This email is confidential and may be privileged. If you are not the intended
recipient of this email you may not use, copy, disclose or rely on the information
contained in it and you must notify the sender immediately on +44 (0)1276 36377
and destroy all copies of this email.

Internet email may be susceptible to data corruption, interception and unauthorised
amendment for which DATA Dialogue does not accept liability. We do not accept
liability for the presence of any computer viruses in this email or any losses
caused as a result of viruses.

Statements in this message that do not relate to our business are neither given nor
endorsed by us.
************************************************************************************
DATA Dialogue, Unit 3 Admiralty Way, Camberley Surrey. GU15 3DT
Phone: 01276 36377 Company Reg:2278708
************************************************************************************
Notice: This email does not constitute agreement for this address to be used
to send me offers of any sort from any party.
Judy Smith

Posts: 2
Registered: 8/19/13
Re: How to calculate EAN-13 barcode check digit
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 18, 2013 9:02 PM   in response to: Andy Colmes in response to: Andy Colmes
Before an EAN-13 symbol may be encoded, the software must compute the correct checksum digit which will be appended to the barcode. The checksum digit is based on a modulo 10 calculation based on the weighted sum of the values of each of the digits in the number system, manufacturer code, and product code. To calculate EAN-13 barcode check digit, first, we take the rightmost digit of the value and consider it to be an "odd" character. We then move right-to-left, alternating between odd and even. We then sum the numeric value of all the even positions, and sum the numeric value multiplied by three of all the odd positions. This can be realized in VB.NET or Delphi.

Edited by: Judy Smith on Aug 18, 2013 9:02 PM

Edited by: Judy Smith on Aug 18, 2013 9:05 PM
john poisy

Posts: 2
Registered: 8/23/13
Re: How to calculate EAN-13 barcode check digit
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 17, 2013 7:23 PM   in response to: Judy Smith in response to: Judy Smith
Judy Smith wrote:
Before an EAN-13 symbol may be encoded, the software must compute the correct checksum digit which will be appended to the barcode. The checksum digit is based on a modulo 10 calculation based on the weighted sum of the values of each of the digits in the number system, manufacturer code, and product code. To calculate EAN-13 barcode check digit, first, we take the rightmost digit of the value and consider it to be an "odd" character. We then move right-to-left, alternating between odd and even. We then sum the numeric value of all the even positions, and sum the numeric value multiplied by three of all the odd positions. This can be realized in VB.NET or Delphi.

Edited by: Judy Smith on Aug 18, 2013 9:02 PM

Edited by: Judy Smith on Aug 18, 2013 9:05 PM
thanks for sharing, that's awesome but somewhat overpriced for me who will just use it only once, do you have some cheaper or even free versions, any suggestion will be appreciated!
Ian Murphy

Posts: 20
Registered: 2/25/00
Re: How to calculate EAN-13 barcode check digit
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 20, 2013 2:49 AM   in response to: john poisy in response to: john poisy
On Tue, 17 Sep 2013 19:23:15 -0700, john poisy <> wrote:

There are online programs that will generate the check digit for you

eg:http://www.barcodesolutions.com.au/checkdigit.html
(I'm not associated with barcode solutions)

regards

Ian

Judy Smith wrote:
Before an EAN-13 symbol may be encoded, the software must compute the correct checksum digit which will be appended to the barcode. The checksum digit is based on a modulo 10 calculation based on the weighted sum of the values of each of the digits in the number system, manufacturer code, and product code. To calculate EAN-13 barcode check digit, first, we take the rightmost digit of the value and consider it to be
an "odd" character. We then move right-to-left, alternating between odd and even. We then sum the numeric value of all the even positions, and sum the numeric value multiplied by three of all the odd positions. This can be realized in VB.NET or Delphi.

Edited by: Judy Smith on Aug 18, 2013 9:02 PM

Edited by: Judy Smith on Aug 18, 2013 9:05 PM
thanks for sharing, that's awesome but somewhat overpriced for me who will just use it only once, do you have some cheaper or even free versions, any suggestion will be appreciated!
arron lee

Posts: 6
Registered: 5/28/13
Re: How to calculate EAN-13 barcode check digit
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 16, 2014 7:49 PM   in response to: john poisy in response to: john poisy
Hi, john poisy.
As for me, I am testing the related online ean-13 barcode generator these days. Do you have any ideas about it? Or any good suggestion? I am totally a green hand on barcode generating field. Any suggestion will be appreciated. Thanks in advance.


Best regards,
Arron

oliver hunt

Posts: 1
Registered: 4/12/13
Re: How to calculate EAN-13 barcode check digit
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 6, 2014 8:55 PM   in response to: arron lee in response to: arron lee
arron lee wrote:
Hi, john poisy.
As for me, I am testing the related online ean-13 barcode generator these days. Do you have any ideas about it? Or any good suggestion? I am totally a green hand on barcode generating field. Any suggestion will be appreciated. Thanks in advance.


Best regards,
Arron


Hey, arron, I think you can get more information by starting a new thread for your question.
Herman vanRuite...

Posts: 31
Registered: 12/6/02
Re: How to calculate EAN-13 barcode check digit [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 19, 2014 4:46 AM   in response to: arron lee in response to: arron lee
Hello Arron,

de cdv of an EAN13 is calculated as folows
example barcode
088358570586x
+ + + + + + = 8+3+8+7+5+6= 37 * 3 = 111
+ + + + + + = 0+8+5+5+0+8= 26 * 1 = 26
together it makes 137. You have to add 3 to have a total in the tens (in
this case 140). This means the cdv = 3.

all even positions together with weight 3
all odd positions together with weight 1

the resulting barcode = 0883585705863

Regards
Herman

arron lee schreef op 17-6-2014 om 4:52:
Hi, john poisy.
As for me, I am testing the related online ean-13 barcode generator these days. Do you have any ideas about it? Or any good suggestion? I am totally a green hand on barcode generating field. Any suggestion will be appreciated. Thanks in advance.


Best regards,
Arron

cin pell

Posts: 3
Registered: 12/11/14
Re: How to calculate EAN-13 barcode check digit
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 23, 2014 8:00 PM   in response to: arron lee in response to: arron lee
arron lee wrote:
Hi, john poisy.
As for me, I am testing the related online ean-13 barcode generator these days. Do you have any ideas about it? Or any good suggestion? I am totally a green hand on barcode generating field. Any suggestion will be appreciated. Thanks in advance.


Best regards,
Arron


Hi, There are some requirements for EAN-13 bar code generation, like date check digit, quiet zone, data and bar code size.
From my experience, I have ever find a bar code generator software for my EAN-13 bar code generation project. And it provided detailed online tutorial:

EAN-13 bar code generator
bar code generation tutorial
Ian Murphy

Posts: 20
Registered: 2/25/00
Re: How to calculate EAN-13 barcode check digit
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 24, 2014 8:17 AM   in response to: cin pell in response to: cin pell
On Sun, 23 Nov 2014 20:00:26 -0800, cin pell <> wrote:

Are you asking how to calculate the ean 13 Check Digit?

Regards

Smurf

arron lee wrote:
Hi, john poisy.
As for me, I am testing the related online ean-13 barcode generator these days. Do you have any ideas about it? Or any good suggestion? I am totally a green hand on barcode generating field. Any suggestion will be appreciated. Thanks in advance.


Best regards,
Arron


Hi, There are some requirements for EAN-13 bar code generation, like date check digit, quiet zone, data and bar code size.
From my experience, I have ever find a bar code generator software for my EAN-13 bar code generation project. And it provided detailed online tutorial:

EAN-13 bar code generator
bar code generation tutorial
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02