Vic D'Elfant Past Contributor
Joined: 26 Jun 2002 Posts: 673 Location: The Netherlands
|
Posted: Sun Aug 29, 2004 3:17 pm Post subject: EAN to ISBN convertor |
|
|
Hi guys,
I had to write this script for a library management program (written in VDS of course ). Perhaps it's useful to any of you... you never know.
It converts the EAN number stored in the barcode at the back of a book to a valid ISBN number. Could be useful if you want to allow your users to scan that barcode to add the book to a database, for example
Code: |
# This variable must hold the number which is stored in the barcode
%%Import = 9780747551003
%%ISBN = @trim(@substr(%%Import, 4, @pred(@len(%%Import))))
%%ISBN_ProdSum = @sum(@prod(@substr(%%ISBN, 1, 1), 10), @prod(@substr(%%ISBN, 2, 2), 9), @prod(@substr(%%ISBN, 3, 3), , @prod(@substr(%%ISBN, 4, 4), 7), @prod(@substr(%%ISBN, 5, 5), 6), @prod(@substr(%%ISBN, 6, 6), 5), @prod(@substr(%%ISBN, 7, 7), 4), @prod(@substr(%%ISBN, 8, , 3), @prod(@substr(%%ISBN, 9, 9), 2))
%i = 0
repeat
%i = @succ(%i)
until @both(@not(@greater(@prod(%i, 11), %%ISBN_ProdSum)), @greater(@prod(@succ(%i), 11), %%ISBN_ProdSum))
%%ISBN_CheckDigit = @diff(11, @diff(%%ISBN_ProdSum, @prod(%i, 11)))
if @equal(%%ISBN_CheckDigit, 11)
%%ISBN_CheckDigit = X
elsif @equal(%%ISBN_CheckDigit, 10)
%%ISBN_CheckDigit = 0
end
%%ISBN = %%ISBN%%ISBN_CheckDigit
info The ISBN number is %%ISBN |
Vic _________________ phpBB Development Team |
|