[RESOLVED] how to calculate EAN8 barcode checksum-VBForums
Results 1 to 6 of 6

Thread: [RESOLVED] how to calculate EAN8 barcode checksum

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2007
    Posts
    106

    Resolved [RESOLVED] how to calculate EAN8 barcode checksum

    hello,
    in my app the user scans a barcode (EAN8) and i need my app to verify that barcode is correct,that is to check the checksum.

    i found online just the algorithm for the EAN13 but no EAN8.Someone worked with this one before?

    thanks

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    87,776

    Re: how to calculate EAN8 barcode checksum

    This is not a VB.NET question. If you have the algorithm and you need help to implement it in VB.NET, THAT is a suitable question for this forum.

    2007-2014

    Why is my data not saved to my database? | MSDN Data Walkthroughs
    MSDN "How Do I?" Videos: VB | C#
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts) | WP8 Turnstile Feather Transition with Pivot Control
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Nov 2007
    Posts
    106

    Re: how to calculate EAN8 barcode checksum

    mmmm, yes , you're right, i think i was searching someone who worked with both vb.net and barcodes.
    my best regards.

  4. #4
    Member
    Join Date
    Mar 2008
    Location
    East Kent, UK
    Posts
    34

    Re: [RESOLVED] how to calculate EAN8 barcode checksum

    Code:
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            MessageBox.Show(EAN8_Checksum("5512345"))
        End Sub
    
        Private Function EAN8_Checksum(ByVal EAN8_Barcode As String) As String
            'http://www.barcodeisland.com/ean8.phtml
    
            Dim ChecksumCalculation As Integer = 0
    
            Dim Position As Int32 = 1
            For i As Integer = EAN8_Barcode.Length - 1 To 0 Step -1
                If Position Mod 2 = 1 Then
                    'odd position
                    ChecksumCalculation += Convert.ToInt32(EAN8_Barcode.Substring(i, 1)) * 3
                Else
                    'even position
                    ChecksumCalculation += Convert.ToInt32(EAN8_Barcode.Substring(i, 1)) * 1
                End If
                Position += 1
            Next
    
            Dim Checksum As Integer = 10 - (ChecksumCalculation Mod 10)
    
            Return Convert.ToString(Checksum)
        End Function

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Nov 2007
    Posts
    106

    Re: [RESOLVED] how to calculate EAN8 barcode checksum

    thank you,the URL you inserted in you're code really help me alot.

  6. #6
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Pointless Forest 38.517,-92.023
    Posts
    7,922

    Re: [RESOLVED] how to calculate EAN8 barcode checksum

    Wish I had paid attention to the dates... This does 8 and 13

    @MattP - got me

    Code:
        Private Function EAN_Checksum(ByVal EAN_Barcode As String, _
                                      Optional eanType As Integer = 8) As String
            Dim oddW As Integer 'odd weighting
            Dim evenW As Integer 'even weighting
            Dim isOdd As Boolean
    
            If eanType = 8 Then 'EAN8
                If EAN_Barcode.Length <> 7 Then
                    'error code needed
                    Throw New Exception
                End If
                oddW = 3
                evenW = 1
                isOdd = True
            ElseIf eanType = 13 Then 'EAN13
                If EAN_Barcode.Length <> 12 Then
                    'error code needed
                    Throw New Exception
                End If
                oddW = 1
                evenW = 3
                isOdd = False
            Else
                'error code needed
                Throw New Exception
            End If
            Dim Checksum As Integer
            'make sure the barcode is numeric
            If Long.TryParse(EAN_Barcode, Nothing) Then
                For Each c As String In EAN_Barcode.Reverse
                    If isOdd Then
                        'odd position
                        Checksum += Integer.Parse(c) * oddW
                    Else
                        'even position
                        Checksum += Integer.Parse(c) * evenW
                    End If
                    isOdd = Not isOdd
                Next
                Checksum = 10 - (Checksum Mod 10)
            Else
                'error code needed
                Throw New Exception
            End If
            Return Checksum.ToString
        End Function
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- SerialPort Answer

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein
    "They who can give up essential liberty to obtain a little temporary safety, deserve neither liberty nor safety." Benjamin Franklin

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.