-
Apr 23rd, 2008, 07:07 AM
#1
Thread Starter
Lively Member
[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
-
Apr 23rd, 2008, 07:58 AM
#2
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.
-
Apr 23rd, 2008, 08:01 AM
#3
Thread Starter
Lively Member
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.
-
Apr 23rd, 2008, 04:01 PM
#4
Member
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
-
Apr 24th, 2008, 03:44 AM
#5
Thread Starter
Lively Member
Re: [RESOLVED] how to calculate EAN8 barcode checksum
thank you,the URL you inserted in you're code really help me alot.
-
Jan 30th, 2013, 10:25 AM
#6
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|