给wps自制dll文件进行身份证号校验

由于工作需要,要对大量的身份证号码进行校验,人工核对非常麻烦,就有了此篇文章,在vb中利用程序作了个dll文件,让wps进行调用,

程序的主要代码来源于网络,主要代码如下:

Function IDcheck(ID)                                                        ‘身份证号码校验函数
Dim s, i As Integer
Dim e, z As String
Part1: ‘—————————-身份证号码合法性检查—————————————
If Not (Len(ID) = 18 Or Len(ID) = 15) Then                                            ‘位数检验
IDcheck = “位数错误”
Exit Function
Else
If Len(ID) = 15 Then ID = Left(ID, 6) & “19” & Right(ID, 9)
If IsNumeric(Left(ID, 17)) = False Or InStr(ID, “.”) > 0 Then                      ‘字符检验
IDcheck = “字符错误”
Exit Function
End If
On Error Resume Next                                                               ‘日期检验
If DateValue(Mid(ID, 7, 4) & “-” & Mid(ID, 11, 2) & “-” & Mid(ID, 13, 2)) < 1 Or _
DateValue(Mid(ID, 7, 4) & “-” & Mid(ID, 11, 2) & “-” & Mid(ID, 13, 2)) > Date Then
IDcheck = “日期错误”
Exit Function
End If
End If
Part2: ‘—————————–校验码的生成及检查—————————————-
s = 0
For i = 1 To 17
s = s + Val(Mid(ID, 18 – i, 1)) * (2 ^ i Mod 11)
Next
e = Mid(“10X98765432”, (s Mod 11) + 1, 1)                                           ‘生成校验码
If Len(ID) = 18 Then
z = UCase(Right(ID, 1))
If z = e Then                                                                    ‘校验码对比
IDcheck = “通过”
Else
IDcheck = “校验未通过”                   ‘如果要返回校验码,请把本行语句改为:IDcheck = e
End If
Else
IDcheck = ID & e                                                         ’15位身份证号码升位
End If
End Function

最后生成dll文件

调用工程如下边的gif动画

IDcheck

文件下载:wps_dll_idcheck

 » 本站地址:http://www.gomoth.com

标签: