チェックディジット計算する
前に戻る
チェックディジットを計算するツールです。
約7~8年ほど前に作ったままですが、使えます。
ご自由にお使いください。
<?xml version="1.0" encoding="shift_JIS"?>
<package>
<component id="keystone">
<registration progid="keystone.jancode"
version="1.0"
clsid="{EDEDC9BA-A05D-4fa1-BCB3-A46CB29922F7}" />
<public>
<method name="calculate_checkdigit" />
</public>
<script language="RubyScript">
<![CDATA[
#author: Keystone kanagawa
#
#内容: チェックディジット計算するだけ
#
def calculate_checkdigit(aBarcode)
wCounter=0
if aBarcode.length != 12
return nil
end
wBarcodeArray=aBarcode.scan(/\d/)
#①454001901226 の場合偶数桁の数値を全部足す
# ~ ~ ~ ~ ~ ~
#5+0+1+0+2+6
wProcess1=0
wBarcodeArray.each_with_index do |itr, index|
index+=1
if index%2==0
wProcess1+=itr.to_i
end
end
#②①の結果を3倍にする
wProcess2=wProcess1*3
#③454001901226 の場合奇数桁の数値を全部足す
# ~ ~ ~ ~ ~ ~
#4+4+0+9+1+2
#このとき右側の1桁は除く
wProcess3=0
wBarcodeArray.each_with_index do |itr, index|
if index%2==0
wProcess3+=itr.to_i
end
end
wProcess4=0
#④②+③
wProcess4=wProcess2+wProcess3
#⑤
wProcess4=wProcess4.to_s
wProcess4=~/(\d+)(\d$)/
if $2.to_i==0
return 0
else
return 10-$2.to_i
end
end
]]>
</script>
</component>
</package>
前に戻る