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.