Digito = 10 - (Soma mod 10)
Digito = 10 - (38 mod 10)
Digito = 10 - 8
Digito = 2
'*** INICIO DO CODIGO ****
'Attribute VB_Name = "ISBNtoEAN"
Public Function TurnISBNToBarcode(ByVal strISBN As String) As String
'''''''''''''''''''''''''''''''''
'
' Written by A P Woods
' Using VB5 Enterprise
' System: General Function
' Dated : 25 04 01
'
' Purpose
'
' Turn an ISBN into a EAN-13 Barcode
'
' Background
'
' A standard ISBN is allocated by ISO (or similar). EAN-13 is a standard barcode format for describing
' a whole raft of barcode groups. In the case of ISBN's the barcode prefix, or leading three digits is 978
' for EAN group "Bookland"
'
' This function checks the entered ISBN string and carries out EAN-13 check sum arithmetic to produce a final
' bar code string
'
' Supporting functions:
'
' GetLeastSignificantDigit (in this module)
'
' Values passed into this function
'
' strISBN passed as a nine digit string, if digits more than nine are passed into the function only the Min nin will be used
'
' Values Returned
'
' If code executes without error: Standard EAN 13 barcode in the form of a string
' If code errors : "Not Valid Bar Code"
'
'
' Possible Modifications
'
' Include function to carry out ISBN checksum validation
'
'
' Revisions
'
' 25 05 01 After checking, substituint "X" for "0" is check sum returns 10.
'
'
'''''''''''''''''''''''''''''''''''''''''''
On Error GoTo errhandler
Dim boolIsValid As Boolean
Dim intOneThreeArray(0 To 12) As Integer
Dim intISBNIntegers(0 To 12) As Integer
Dim intBarCodeResult(0 To 12) As Integer
Dim intCheckSum As Integer
Dim intResult As Integer
Dim intLoopCounter As Integer
boolIsValid = True
''''''''''''''''''''''
'
' if passed strISBN value is more than nine characters, strip out the excess to get rid of the ISBN checksum
'
'''''''''''''''''''''
If Len(Trim(strISBN)) > 9 Then
strISBN = Left(Trim(strISBN), 9)
End If
''''''
'
' Fill in the onethreearray array
'
'''''
intOneThreeArray(0) = 1
intOneThreeArray(1) = 3
intOneThreeArray(2) = 1
intOneThreeArray(3) = 3
intOneThreeArray(4) = 1
intOneThreeArray(5) = 3
intOneThreeArray(6) = 1
intOneThreeArray(7) = 3
intOneThreeArray(8) = 1
intOneThreeArray(9) = 3
intOneThreeArray(10) = 1
intOneThreeArray(11) = 3
''''
'
' pad out the passed ISBN to ten characters
'
''''
If boolIsValid = True Then
If Len(Trim(strISBN)) < 9 Then
Do While Len(Trim(strISBN)) < 9
strISBN = strISBN + "0"
Loop
End If
'''''''''''''''''''''''''''''''
'
' Now add the BOOKLAND EAN Prefix "978" to strISBN
'
''''''''''''''''''''''''''''''''
strISBN = "978" + strISBN
''''''''''''''''''''''''''''''''
'
' Now do the EAN-13 check sum
'
''''''''''''''''''''''''''''''''
For intLoopCounter = 0 To 11
On Error Resume Next
intISBNIntegers(intLoopCounter) = CInt(Mid(strISBN, intLoopCounter + 1, 1))
intBarCodeResult(intLoopCounter) = intISBNIntegers(intLoopCounter) * intOneThreeArray(intLoopCounter)
intResult = intResult + intBarCodeResult(intLoopCounter)
Next intLoopCounter
''''''''''''''''''''''''''''''
'
' Get the checksum least significant digit
'
'''''''''''''''''''''''''''''
intCheckSum = GetLeastSignificantDigit(intResult)
intCheckSum = 10 - intCheckSum
''''''''''''
'
' barcode result is strISBN plus the checksum converted to a string
' Note, the rules state that if the result of the checksum is 10 then the check digit appended to the bar code is an uppercase "X"
'
'
'
''''''''''''
If intCheckSum = 10 Then
TurnISBNToBarcode = strISBN + "0"
Else
TurnISBNToBarcode = strISBN + Trim(CStr(intCheckSum))
End If
Else
TurnISBNToBarcode = "Invalid ISBN Code"
End If
Exit Function
errhandler:
On Error GoTo 0
TurnISBNToBarcode = "Invalid ISBN Code"
End Function
Public Function GetLeastSignificantDigit(ByVal lgResult As Long) As Integer
On Error GoTo errhandler
Dim strResult As String
strResult = Trim(CStr(lgResult))
If Len(Trim(strResult)) > 1 Then
GetLeastSignificantDigit = CInt(Trim(Right(strResult, 1)))
Else
GetLeastSignificantDigit = CInt(Trim(strResult))
End If
Exit Function
errhandler:
GetLeastSignificantDigit = -1
End Function
agora é só testar !