The International Standard Book Number (ISBN) is a unique commercial book identifier barcode. If you work with VB.NET applications that deal with books, you’re all-too-familiar with the task of confirming that a given ISBN value is valid.

Prior to 2007, ISBN consisted of 10-digit values; beginning this year, 13 digit ISBN numbers are used. The sample VB.NET code shows how to validate a 10 digit and a 13 digit ISBN value. (Note: The sample is not intended to be used in applications as-is — it simply explains the basics of confirming an ISBN number is valid. Modify the code to best fit your needs.) I define variables to calculate both 10 digit and 13 digit ISBN values. Since the calculation techniques are slightly different for each type of ISBN, I use a separate set of variables for each type. The example hard codes two ISBN values — one 10 digit and one 13 digit. Both values are valid ISBN numbers, and the code displays a message box for each ISBN value stating that it’s valid. If you were to substitute the valid ISBN values with invalid numbers, the resulting message boxes would display corresponding messages.

The example defines variables to check any type of ISBN value to facilitate a better understanding of the code. However, you may want to create a function that will accept an ISBN value as a parameter, and then check whether the ISBN value passed has 10 or 13 digits, perform appropriate verification, and return the outcome of the verification.

Check out Wikipedia for more information on usage and verification of ISBNs.

Irina Medvinskaya has been involved in technology since 1996. She has an MBA from Pace University and works as a Project Manager at Citigroup.


Get Visual Basic tips in your inbox

Advance your scripting skills to the next level with TechRepublic’s free Visual Basic newsletter, delivered each Friday. Automatically subscribe today!