Page 1 of 1

Re: Short version of IFSDB.ORG book query

Posted: Mon Dec 01, 2008 6:23 am
by Mohawk70
graves wrote:
Fangbeast wrote:ISBNnumber.s = "0552151769"
Do you know that the ISBN number has changed from 10 to 13 digits (EAN)?

Now this ISBN is : "9780552151764"
Here's my contribution - an ISBN-10 to ISBN-13 Conversion procedure !

Code: Select all

Procedure.s ISBN10toISBN13(in.s)
  ;Convert ISBN-10 To ISBN-13
	out.s = in.s
  in.s = ""
	For i = 1 To Len(out.s)
		If FindString("0123456789",Mid(out.s,i,1),1)
			in.s + Mid(out.s,i,1)
		EndIf
	Next
	out.s = in.s
	r = #True
	If Len(in.s) = 10
		For i = 1 To 9
			p = FindString("0123456789",Mid(in.s,i,1),1)
			If p = 0
				r = #False
			EndIf
		Next
	Else
		r = #False
	EndIf
	Select r
		Case #False
			sOut.s = out.s
		Case #True
			out.s = "978" + Left(in.s,9)
			n = 0
			For i = 1 To 12
				oe = i % 2
				Select oe
					Case 1;Odd
						n + Val(Mid(out.s,i,1))
					Case 0;Even
						n + 3 * (Val(Mid(out.s,i,1)))
				EndSelect
			Next
			m = 10 - (n % 10)
			sOut.s = out.s + Str(m)
	EndSelect
	ProcedureReturn sOut.s
EndProcedure


;Examples
ISBN10.s = "0552151769"
ISBN13.s = ISBN10toISBN13(ISBN10.s)
MessageRequester("ISBN-10 to ISBN-13 Conversion","ISBN-10 : " + ISBN10.s + Chr(10) + "ISBN-13 : " + ISBN13.s,80)

ISBN10.s = "0826412769"
ISBN13.s = ISBN10toISBN13(ISBN10.s)
MessageRequester("ISBN-10 to ISBN-13 Conversion","ISBN-10 : " + ISBN10.s + Chr(10) + "ISBN-13 : " + ISBN13.s,80)

ISBN10.s = "0451204298"
ISBN13.s = ISBN10toISBN13(ISBN10.s)
MessageRequester("ISBN-10 to ISBN-13 Conversion","ISBN-10 : " + ISBN10.s + Chr(10) + "ISBN-13 : " + ISBN13.s,80)

ISBN10.s = "0670037796"
ISBN13.s = ISBN10toISBN13(ISBN10.s)
MessageRequester("ISBN-10 to ISBN-13 Conversion","ISBN-10 : " + ISBN10.s + Chr(10) + "ISBN-13 : " + ISBN13.s,80)

End
[/code]

:D

Posted: Wed Dec 03, 2008 12:27 am
by Mohawk70
:oops: :oops: :oops:

I found out after my original post that

000100686X

&

157500111X

are also valid ISBN-10 numbers !

Fixed code below

Code: Select all

Procedure.l IsISBN10(in.s)
	check.s = ""
	n.l = 0
	l.l = Len(in.s)
	If l.l = 10
		For i = 1 To 9
			weight.l = 11 - i
			n.l = n.l + (weight.l * Val(Mid(in,i,1)))
		Next
		c.l = 11-(n%11)
		If c.l = 10
			check.s = Left(in,9) + "X"
		Else
			check.s = Left(in,9) + Str(c)
		EndIf
		If check.s = in.s
			lOut.l = #True
		Else
			lOut.l = #False
		EndIf
	Else
		lOut.l = #False
	EndIf
	ProcedureReturn lOut.l
EndProcedure

Procedure.s ISBN10toISBN13(in.s)
	sOut.s = ""
	ok.l = 0
	n.l = 38
	If Len(in) = 10
		For i = 1 To 9
			If FindString("0123456789",Mid(in,i,1),1)
				ok + 1
				If i < 10
					If i%2 = 0
						n + Val(Mid(in,i,1))
					Else
						n + (3 * Val(Mid(in,i,1)))
					EndIf
				EndIf
			EndIf
		Next
		If FindString("0123456789X",Right(in,1),1)
			ok + 1
		EndIf
		If ok = 10
			m.l = 10 - ( n % 10)
			If m = 10
				sOut.s = "978" + Left(in,9) + "0"
			Else
				sOut.s = "978" + Left(in,9) + Str(10-(n%10))
			EndIf
		EndIf
	EndIf
	ProcedureReturn sOut.s
EndProcedure

;Examples (Legitimate ISBN-10 #s)
ISBN10.s = "000100686X"
If IsISBN10(ISBN10.s) = #True
	ISBN13.s = ISBN10toISBN13(ISBN10.s)
	MessageRequester("ISBN-10 to ISBN-13 Converter",ISBN10.s + Chr(10) + ISBN13.s,80)
Else
	MessageRequester("ISBN-10 to ISBN-13 Converter","ERROR!" + Chr(10) + "INVALID INPUT",16)
EndIf

ISBN10.s = "157500111X"
If IsISBN10(ISBN10.s) = #True
	ISBN13.s = ISBN10toISBN13(ISBN10.s)
	MessageRequester("ISBN-10 to ISBN-13 Converter",ISBN10.s + Chr(10) + ISBN13.s,80)
Else
	MessageRequester("ISBN-10 to ISBN-13 Converter","ERROR!" + Chr(10) + "INVALID INPUT",16)
EndIf

ISBN10.s = "0826412769"
If IsISBN10(ISBN10.s) = #True
	ISBN13.s = ISBN10toISBN13(ISBN10.s)
	MessageRequester("ISBN-10 to ISBN-13 Converter",ISBN10.s + Chr(10) + ISBN13.s,80)
Else
	MessageRequester("ISBN-10 to ISBN-13 Converter","ERROR!" + Chr(10) + "INVALID INPUT",16)
EndIf

ISBN10.s = "0445203498"
If IsISBN10(ISBN10.s) = #True
	ISBN13.s = ISBN10toISBN13(ISBN10.s)
	MessageRequester("ISBN-10 to ISBN-13 Converter",ISBN10.s + Chr(10) + ISBN13.s,80)
Else
	MessageRequester("ISBN-10 to ISBN-13 Converter","ERROR!" + Chr(10) + "INVALID INPUT",16)
EndIf

ISBN10.s = "0684823802"
If IsISBN10(ISBN10.s) = #True
	ISBN13.s = ISBN10toISBN13(ISBN10.s)
	MessageRequester("ISBN-10 to ISBN-13 Converter",ISBN10.s + Chr(10) + ISBN13.s,80)
Else
	MessageRequester("ISBN-10 to ISBN-13 Converter","ERROR!" + Chr(10) + "INVALID INPUT",16)
EndIf

ISBN10.s = "0552151769"
If IsISBN10(ISBN10.s) = #True
	ISBN13.s = ISBN10toISBN13(ISBN10.s)
	MessageRequester("ISBN-10 to ISBN-13 Converter",ISBN10.s + Chr(10) + ISBN13.s,80)
Else
	MessageRequester("ISBN-10 to ISBN-13 Converter","ERROR!" + Chr(10) + "INVALID INPUT",16)
EndIf

ISBN10.s = "0060263857"
If IsISBN10(ISBN10.s) = #True
	ISBN13.s = ISBN10toISBN13(ISBN10.s)
	MessageRequester("ISBN-10 to ISBN-13 Converter",ISBN10.s + Chr(10) + ISBN13.s,80)
Else
	MessageRequester("ISBN-10 to ISBN-13 Converter","ERROR!" + Chr(10) + "INVALID INPUT",16)
EndIf


;Examples (Illegitimate ISBN-10 #s)
ISBN10.s = "1234567890"
If IsISBN10(ISBN10.s) = #True
	ISBN13.s = ISBN10toISBN13(ISBN10.s)
	MessageRequester("ISBN-10 to ISBN-13 Converter",ISBN10.s + Chr(10) + ISBN13.s,80)
Else
	MessageRequester("ISBN-10 to ISBN-13 Converter","ERROR!" + Chr(10) + "INVALID INPUT",16)
EndIf

ISBN10.s = "123456788X"
If IsISBN10(ISBN10.s) = #True
	ISBN13.s = ISBN10toISBN13(ISBN10.s)
	MessageRequester("ISBN-10 to ISBN-13 Converter",ISBN10.s + Chr(10) + ISBN13.s,80)
Else
	MessageRequester("ISBN-10 to ISBN-13 Converter","ERROR!" + Chr(10) + "INVALID INPUT",16)
EndIf

End

Posted: Wed Dec 03, 2008 9:25 am
by graves
Good job.
You know this procedure is valid only for a few years, until ISBN EAN starts with "979...".
At this point no more translations between EAN-13 and ISBN-10 can be done. EAN-13 with 979 no will have translation to old ISBN-10.

Posted: Sat Dec 06, 2008 6:20 am
by Mohawk70
graves wrote:Good job.
You know this procedure is valid only for a few years, until ISBN EAN starts with "979...".
At this point no more translations between EAN-13 and ISBN-10 can be done. EAN-13 with 979 no will have translation to old ISBN-10.
Not a problem. This was just intended as a tool to convert ISBN-10 to the 13 Digit format for anyone who needed it!

Posted: Sat Dec 06, 2008 10:04 am
by graves
Hi,
Thit's my own procedure to check data entry and convert ISBN 10 to EAN 13:

Code: Select all

;-------------------------------------------------------------------------------
; Edit ISBN-EAN in 5 groups
;-------------------------------------------------------------------------------
;
; ISBN-EAN 13 digits structure               
;      group 1 : 3 digits                         
;      group 2 : 1 to 5 digits                     
;                      0 - 7
;                     80 - 94
;                    950 - 994
;                   9950 - 9989
;                  99900 - 99999
;      group 3 : 2 to 7 digits                     
;                     00 - 19
;                    200 - 699
;                   7000 - 8499
;                  85000 - 89999
;                 900000 - 949999
;                9500000 - 9999999
;      group 4 : 1 to 5 digits 
;      group 5 : 1 control digit
;
; CONTROL DIGIT CALC
; EAN 13       :  result = ((digits 2+4+6+8+10+12) * 3) + (digits 1+3+5+7+9+11)
; Complementary:  10 - (result % 10)
;    if it's 10:  get "0"
;
; ISBN 10      : result = (dig1*10)+(dig2*9)+(dig3*8)+(dig4*7)+(dig5*6)
;                                  +(dig6*5)+(dig7*4)+(dig8*3)+(dig9*2)
; Complementary:  11 - (result % 11)
;    if it's 10:  get "X"
;    if it's 11:  get "0"
;
; Separator Parameter:
;      Null: return ISBNEAN 13 without separators (data entry)
;      "*" : return only Publisher code without separators
;      "+" : return only Publisher with "-" separator
;     other: return ISBNEAN 13 with separator
;
;-------------------------------------------------------------------------------
macro between(btwfld, btwfrm, btwto)
  btwfld >= btwfrm AND btwfld <= btwto
endmacro

Procedure.s l_EditIsbn(isbnean.s, sep.s="")
  procret.s = ""
  isbnean  = trim(isbnean)
  idx  = 0
  idy  = 0
  idz  = 0

  if len(isbnean) = 9   ; incomplete ISBN 10 (add a "X" as control code, even isn't correct)
    isbnean + "X"
  endif
  if len(isbnean) = 10  ; complete ISBN 10
    sumadd = 0
    for n=1 to 9
      sumadd + (val(mid(isbnean,n,1)) * (11-n))
    next
    chkd.s  = str(11-(sumadd % 11))
    if chkd = "10": chkd = "X": endif
    if chkd = "11": chkd = "0": endif
    if mid(isbnean,10,1) = chkd
      isbnean = "978"+mid(isbnean,1,9)
    endif
  endif

  if len(isbnean) = 12 OR len(isbnean) = 13  ; complete EAN 13 even without control code
    sumadd = val(mid(isbnean,2,1))+val(mid(isbnean, 4,1))+val(mid(isbnean, 6,1))
    sumadd + val(mid(isbnean,8,1))+val(mid(isbnean,10,1))+val(mid(isbnean,12,1))
    sumadd * 3
    sumadd + val(mid(isbnean,1,1))+val(mid(isbnean, 3,1))+val(mid(isbnean, 5,1))
    sumadd + val(mid(isbnean,7,1))+val(mid(isbnean, 9,1))+val(mid(isbnean,11,1))
    chkd    = str(10-(sumadd % 10))
    if chkd = "10": chkd = "0": endif
    if len(isbnean) = 12 :   isbnean = isbnean + chkd: idz = sumadd: endif
    if len(isbnean) = 13 AND mid(isbnean,13,1) = chkd: idz = sumadd: endif
  endif

  if idz
    if len(sep)
      if     between(mid(isbnean,4,1),    "0",    "7"): idx = 1
      elseif between(mid(isbnean,4,2),   "80",   "94"): idx = 2
      elseif between(mid(isbnean,4,3),  "950",  "994"): idx = 3
      elseif between(mid(isbnean,4,4), "9950", "9989"): idx = 4
      elseif between(mid(isbnean,4,5),"99900","99999"): idx = 5
      endif
      if idx
        if     between(mid(isbnean,idx+4,2),     "00",     "19"): idy = 2
        elseif between(mid(isbnean,idx+4,3),    "200",    "699"): idy = 3
        elseif between(mid(isbnean,idx+4,4),   "7000",   "8499"): idy = 4
        elseif between(mid(isbnean,idx+4,5),  "85000",  "89999"): idy = 5
        elseif between(mid(isbnean,idx+4,6), "900000", "949999"): idy = 6
        elseif between(mid(isbnean,idx+4,6),"9500000","9999999"): idy = 7
        endif
        if idy
          if sep = "*"
            procret = mid(isbnean,4,idx)+mid(isbnean,idx+4,idy)      ; procret only Publisher code without separators
          elseif sep = "+"
            procret = mid(isbnean,4,idx)+"-"+mid(isbnean,idx+4,idy) ; procret only Publisher with "-" separator
          else
            idz = 9 - idx - idy                                     ; procret ISBNEAN 13 with separator
            procret = left(isbnean,3)+sep
            procret + mid(isbnean,4,idx)+sep
            procret + mid(isbnean,idx+4,idy)+sep
            procret + mid(isbnean,idx+idy+4,idz)+sep
            procret + right(isbnean,1)
          endif
        endif
      endif
    else
      procret = isbnean                                              ; procret ISBNEAN 13 without separators (data entry)
    endif
  endif
  ProcedureReturn procret
EndProcedure
edited and corrected.