AppleScript名:JANコードのチェックデジットの計算 |
set aData to "240469540245" –女性用カジュアルパンプス(黒) set aSum to calcJANcodeChkSum(aData) –> 9 set aData to "978479731648" –「Mac使いへの道」 set aSum to calcJANcodeChkSum(aData) –> 3 –JANコードのチェックデジットの計算 –参照元:http://www.kabukoba.co.jp/info/barcode/check.htm on calcJANcodeChkSum(aData) set aList to characters of aData if length of aList is not equal to 12 then return false set kiSnum to 0 set guNum to 0 repeat with i from 2 to length of aList set kiSuF to ((i – 1) mod 2) set j to (item i of aList) as number if kiSuF = 1 then –奇数 set kiSnum to kiSnum + j else –偶数 set guNum to guNum + j end if end repeat set kiSnum to kiSnum * 3 set guNum to guNum + (first item of aList) as number set totalNum to kiSnum + guNum set totalChar to totalNum as string set lastDig to (last character of totalChar) as number if lastDig is not equal to 0 then set sumNum to 10 – lastDig else set sumNum to 0 end if return sumNum end calcJANcodeChkSum |
(Visited 51 times, 1 visits today)