Dynamically calculating a check digit.

Mr Clevver

Idiot Savant
Local time
Today, 10:12
Joined
Jun 26, 2008
Messages
17
Hi all.


I'm looking for some help automating the process of converting ISBN10s* to ISBN13s in a book database that I'm currently working on. ISBN13s are pretty much the same as an ISBN10, but are prefaced with 978 and, here's the rub, the last digit is a check digit that is dynamically calculted from the previous 12, using the formula:

[10-([9+(3*7)+8+X1+3X2+X3+3X4+X5+3X6+X7+3X8+X9+3X10+X11+3X12]Mod10)]Mod10
Where X1 is the first digit of the 10 digit ISBN, X2 is the second etc.

All that is academic really, as I'm struggling with the very first stage, which is splitting the ISBN10 into individual digits, so I can assign them to the variables X1, X2 etc.

I've tried using the Split() function, but am struggling with this as the data doesn't have any delimiters. I thought maybe arrays would be the way to go, but am struggling to find a decent overview of their workings.

Any help would be much appreciated.


*ISBN10 and 13 are unique identifiers given to books. ISBN13s are the new standard, with the ISBN10s slowly being faded out.
 
using the Do While and Mid functions you can take 1 character each time from your ISBN number.

Then use a "Select case" to do different calculations to the different didgets.

I hope that gets you going, if not ask away.
 
mr clevver

slice your string with mid

mid(mystring, 4,1)

in this case, it returns a string of length 1 char, starting at the 4th char

to convert this to a number you need

cint(mid(mystring, 4,1))

-----------
so have a function called

function getdigit(isbn as string, charnum) as integer
getdigit = cint(mid(isbn, charnum,1))
end function

and the you can say

mynum = (getdigit(x,1)+3*getdigit(x,2)+etc) mod 10

there is a function mod, so you shouldnt have much trouble

there is no error checking for bad isbn numbers in this (or bad characters in the string)
 
Thanks!
I've managed to get the program doing what I need it to now (with the addition of a check to see if the last digit is an X or x, which represents the value 10 in the check digit calculation).

I should be able to use the mid() function to do the reverse (convert ISBN13s into ISBN10s), and also to check whether ISBNs entered are valid.

Thanks again.
 

Users who are viewing this thread

Back
Top Bottom