Modul Checksum EAN8 dan EAN13 (Barcode)

Source dibawah ini adalah cara menghitung checksum EAN8 dan EAN13,  ok langsung saja :

========================Start========================

Option Explicit
Public Enum GenerateBarcode_
EAN8 = 0
EAN13 = 1
End Enum
Public Function GenerateBarcode(ByVal Tipe As GenerateBarcode_, ByVal barcode As String) As String
GenerateBarcode = IIf(Tipe = EAN8, EAN8_Checksum(barcode), Append_EAN13_Checksum(barcode))
End Function
 

Public Function EAN8_Checksum(ByVal EAN8_Barcode As String) As String
Dim ChecksumCalculation As Integer
ChecksumCalculation = 0
Dim Position As Integer
Position = 1
Dim i As Integer
For i = Len(EAN8_Barcode) – 1 To 0 Step -1
If Position Mod 2 = 1 Then
‘odd position
ChecksumCalculation = ChecksumCalculation + CLng(Mid(EAN8_Barcode, i + 1, 1)) * 3
Else
‘even position
ChecksumCalculation = ChecksumCalculation + CLng(Mid(EAN8_Barcode, i + 1, 1)) * 1
End If
Position = Position + 1
Next
Dim Checksum As Integer
Checksum = (10 – (ChecksumCalculation Mod 10)) Mod 10
EAN8_Checksum = Format(Checksum, “0”)
End Function
Public Function Append_EAN13_Checksum(RawString As String)
Dim Position As Integer
Dim Checksum As Integer
Checksum = 0
For Position = 2 To 12 Step 2
Checksum = Checksum + Val(Mid$(RawString, Position, 1))
Next Position
Checksum = Checksum * 3
For Position = 1 To 11 Step 2
Checksum = Checksum + Val(Mid$(RawString, Position, 1))
Next Position
Checksum = Checksum Mod 10
Checksum = 10 – Checksum
If Checksum = 10 Then
Checksum = 0
End If
Append_EAN13_Checksum = RawString & Format$(Checksum, “0”)
End Function

Option Explicit
Public Enum GenerateBarcode_  EAN8 = 0  EAN13 = 1End Enum
Public Function GenerateBarcode(ByVal Tipe As GenerateBarcode_, ByVal barcode As String) As String  GenerateBarcode = IIf(Tipe = EAN8, EAN8_Checksum(barcode), Append_EAN13_Checksum(barcode))End Function

Public Function EAN8_Checksum(ByVal EAN8_Barcode As String) As String      ‘http://www.barcodeisland.com/ean8.phtml
Dim ChecksumCalculation As Integer      ChecksumCalculation = 0      Dim Position As Integer      Position = 1      Dim i As Integer      For i = Len(EAN8_Barcode) – 1 To 0 Step -1          If Position Mod 2 = 1 Then              ‘odd position              ChecksumCalculation = ChecksumCalculation + CLng(Mid(EAN8_Barcode, i + 1, 1)) * 3          Else              ‘even position              ChecksumCalculation = ChecksumCalculation + CLng(Mid(EAN8_Barcode, i + 1, 1)) * 1          End If          Position = Position + 1      Next
Dim Checksum As Integer      Checksum = (10 – (ChecksumCalculation Mod 10)) Mod 10
EAN8_Checksum = Format(Checksum, “0”)    End Function

Public Function Append_EAN13_Checksum(RawString As String)    Dim Position As Integer    Dim Checksum As Integer
Checksum = 0    For Position = 2 To 12 Step 2          Checksum = Checksum + Val(Mid$(RawString, Position, 1))    Next Position    Checksum = Checksum * 3    For Position = 1 To 11 Step 2         Checksum = Checksum + Val(Mid$(RawString, Position, 1))    Next Position    Checksum = Checksum Mod 10    Checksum = 10 – Checksum    If Checksum = 10 Then         Checksum = 0    End If    Append_EAN13_Checksum = RawString & Format$(Checksum, “0”)End Function

========================END========================

 

Atau download aja detilnya ada di BARCODE. (rename dulu .doc ke .rar ya) :))

  1. No trackbacks yet.

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: