Versions: 97 +

If you have any databases that store information about books, you'll want someway of verifying ISBN entries. I'm not going to elaborate more about how ISBNs work, suffice to say they use modulus 11 maths. If you're really desperate to know, you can read all about it here. Anyway, this function takes one parameter, the ISBN value, and returns True if it's a valid ISBN, False otherwise.

Function CheckISBN(x As Variant) As Boolean
    'Code sample from Accessory http://www22.brinkster.com/accessory
    Dim bLen As Byte, iCnt As Integer, iVal As Integer
    bLen = Len(x)
    If bLen > 10 Or bLen = 0 Then GoTo Invalid_CheckISBN 'Number is too long or too short
    iVal = 0
    For iCnt = 10 To 1 Step -1
        If iCnt <= bLen Then
            iVal = iVal + (iCnt * Mid(x, ((-1 * iCnt) + bLen + 1), 1))
        End If
    Next iCnt
    CheckISBN = (iVal Mod 11 = 0)

Exit_CheckISBN:
    Exit Function

Invalid_CheckISBN:
    CheckISBN = False
    GoTo Exit_CheckISBN
End Function

Site requires Javascript and IFRAME support.
Visitors:
© Accessory 2001-.
Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 2.5 License.