如何在EXCEL表里加载统一社会信用代码效验函数
打开EXCEL表,进入“工具—宏—Visual Basic编辑器”,在“工程资源管理器”插入模块(如模块1),在模块1代码框里加载如下代码:
Function tydm(in_tydm, bz)
in_tydm = Trim(in_tydm)
TC = "0123456789ABCDEFGHJKLMNPQRTUWXY0"
tcer = ""
te = Len(in_tydm)
For ti = 1 To te
If InStr(TC, Mid(in_tydm, ti, 1)) < 1 Or ti > 18 Then
tcer = tcer + Mid(in_tydm, ti, 1) + "(" + Trim(Str(ti)) + ")"
End If
Next
If Len(in_tydm) < 17 Then
te = Len(in_tydm)
Else
te = 17
End If
tm = 0
If bz = 1 Then
If Len(Trim(tcer)) = 0 And te = 17 Then
For ti = 1 To te
tm = tm + (InStr(TC, Mid(in_tydm, ti, 1)) - 1) * ((3 ^ (ti - 1)) Mod 31)
Next
tydm = Mid(in_tydm, 1, 17) + Mid(TC, 31 - (tm Mod 31) + 1, 1)
Else
tydm = ""
End If
End If
If bz = 2 Then
If Len(Trim(tcer)) = 0 And te = 17 Then
For ti = 1 To te
tm = tm + (InStr(TC, Mid(in_tydm, ti, 1)) - 1) * ((3 ^ (ti - 1)) Mod 31)
Next
If Mid(in_tydm, 18, 1) = Mid(TC, 31 - (tm Mod 31) + 1, 1) Then
tydm = "√"
Else
tydm = "×:(18)=" + Mid(TC, 31 - (tm Mod 31) + 1, 1)
End If
Else
If te < 17 Then
tydm = "×:" & te
Else
tydm = "×:" + tcer
End If
End If
End If
End Function
另存文件,这个文件含有了TYDM(统一社会信用代码,1[2])函数了。TYDM(统一社会信用代码,1)值为该代码前17位和依前17位计算的1位效验码,以便比较;TYDM(统一社会信用代码,2)值为“√”(效验通过)或“×”(效验不通过)。
泉州调查队 杨景富
二〇一六年四月十二日