'================================计算身份证第18位校检码
Public Type AboutIdCard
Place As String '地区
Sex As String '性别
Birthday As Date '生日
sErrInfo As String '错误信息
End Type
Public Function GetPersonInfo(CodePath As String, idcard As String, BackInfo As AboutIdCard) As String
'根据〖中华人民共和国国家标准 GB 11643-1999〗中有关公民身份号码的规定,
'公民身份号码是特征组合码18位:由十七位数字本体码和一位数字校验码组成。排列顺序从左至右依次为:六位数字地址码,八位数字出生日期码,三位数字顺序码和一位数字校验码。
'地址码表示编码对象常住户口所在县(市、旗、区)的行政区划代码。生日期码表示编码对象出生的年、月、日,其中年份用四位数字表示,年、月、日之间不用分隔符。顺序码表示同一地址码所标识的区域范围内,对同年、月、日出生的人员编定的顺序号。顺序码的奇数分给男性,偶数分给女性。
'15位:六位数字地址码,六位数字出生日期码,三位数字顺序码和一位数字校验码。
On Error GoTo Err:
Dim PlaceCode As String
Dim strPlace As String
Dim strCode As String
Dim sDate As String
Dim FileNumber As Long
GetPersonInfo = ""
BackInfo.sErrInfo = ""
If Len(idcard) <> 15 And Len(idcard) <> 18 Then
BackInfo.sErrInfo = "身份证长度错误"
End If
'判断日期/转换成为日期,出错跳转
If Len(idcard) = 15 Then
sDate = Mid(idcard, 7, 2) & "-" & Mid(idcard, 9, 2) & "-" & Mid(idcard, 11, 2)
BackInfo.Birthday = Format(sDate, "yyyy-mm-dd")
If CLng(Mid(idcard, 13, 3)) Mod 2 = 0 Then '取得性别
BackInfo.Sex = "女"
Else
BackInfo.Sex = "男"
End If
Else
sDate = Mid(idcard, 7, 4) & "-" & Mid(idcard, 11, 2) & "-" & Mid(idcard, 13, 2)
BackInfo.Birthday = sDate
If CLng(Mid(idcard, 15, 3)) Mod 2 = 0 Then '取得性别
BackInfo.Sex = "女"
Else
BackInfo.Sex = "男"
End If
End If
PlaceCode = Mi