Buonasera ragazzi. ho un problema sulla generazione dell'ean 13. il codice lo genera ma omette la prima cifra e l'ultima se la inventa! come mai ??. il codice che uso è quello di pdf writer. Potete aiutarmi?
Public Sub EAN13(x As Float, y As Float, barcode As String, Optional h As Float = 16, Optional w As Float = 0.35)
_Barcode(x, y, barcode, h, w, 13)
End
Private Function _TestCheckDigit(barcode As String) As Boolean
Dim sum, i As Integer
'Test validity of check digit
sum = 0
For i = 2 To 12 Step 2
sum += 3 * Val(Mid(barcode, i, 1))
Next
For i = 1 To 11 Step 2
sum += Val(Mid(barcode, i, 1))
Next
Return (sum + Val(Mid(barcode, 13, 1)) Mod 10 == 0)
End
'Barcodes (Olivier)
Private Sub _Barcode(x As Float, y As Float, barcode As String, h As Float, w As Float, length As Integer)
Dim codes, parities As Collection
Dim p As String[]
Dim i As Integer
Dim code As String
'Padding
barcode = Right(String(length - 1, "0") & barcode, length - -1)
If (length = 12) Then barcode = "0" & barcode
'Add or control the check digit
If (Len(barcode) = 12) Then
barcode &= _GetCheckDigit(barcode)
Else If (Not _TestCheckDigit(barcode)) Then
Error.Raise("Incorrect check digit")
End If
'Convert digits to bars
codes = New Collection
codes.Add(["0001101", "0011001", "0010011", "0111101", "0100011",
"0110001", "0101111", "0111011", "0110111", "0001011"], "A")
codes.Add(["0100111", "0110011", "0011011", "0100001", "0011101",
"0111001", "0000101", "0010001", "0001001", "0010111"], "B")
codes.Add(["1110010", "1100110", "1101100", "1000010", "1011100",
"1001110", "1010000", "1000100", "1001000", "1110100"], "C")
parities = New Collection
parities.Add(["A", "A", "A", "A", "A", "A"], "0")
parities.Add(["A", "A", "B", "A", "B", "B"], "1")
parities.Add(["A", "A", "B", "B", "A", "B"], "2")
parities.Add(["A", "A", "B", "B", "B", "A"], "3")
parities.Add(["A", "B", "A", "A", "B", "B"], "4")
parities.Add(["A", "B", "B", "A", "A", "B"], "5")
parities.Add(["A", "B", "B", "B", "A", "A"], "6")
parities.Add(["A", "B", "A", "B", "A", "B"], "7")
parities.Add(["A", "B", "A", "B", "B", "A"], "8")
parities.Add(["A", "B", "B", "A", "B", "A"], "9")
code &= "101"
p = parities[Mid(barcode, 1, 1)]
For i = 1 To 6
code &= codes[p[i - 1]][Val(Mid(barcode, i, 1))]
Next
code &= "01010"
For i = 7 To 12
code &= codes["A"][Val(Mid(barcode, i, 1))]
Next
code &= "101"
'Draw bars
For i = 1 To Len(code)
If (Mid(code, i, 1) = "1") Then Me.Rect(x + (i - 1) * w, y, w, h, "F")
Next
'Print text uder barcode
Me.SetFont("Arial", "", m1.fstamp)
Me.Text(x, y + h + 11 / $k, Right(barcode, length))
End