原来还可以如此计算的。 看到过别人编写的代码如下。 好像17个相乘计算的权重代码值不一样的哦。 Private Function getCheckCode(ByVal sfID As String) As String | '身份证号码升位和校验函数 | ' | '输入15位号码返回18位新号码 | '输入18位号码计算是否正确,如果正确返回原号码否则返回"错误" | '如果号码长度不等于15或18位返回"错误" | ' | Dim strJiaoYan As Variant | Dim intQuan As Variant | strJiaoYan = Array("1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2") | intQuan = Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1) | Dim strTemp As String | Dim intTemp As Integer | Dim i As Integer | If Len(sfID) = 15 Then | strTemp = Mid(sfID, 1, 6) & "19" & Mid(sfID, 7) | ElseIf Len(sfID) = 18 Then | strTemp = Left(sfID, 17) | Else | getCheckCode = "错误" | Exit Function | End If | For i = 0 To Len(strTemp) - 1 | intTemp = intTemp + Mid(strTemp, i + 1, 1) * intQuan(i) | Next | intTemp = intTemp Mod 11 | getCheckCode = strTemp & strJiaoYan(intTemp) | If Len(sfID) = 18 And strJiaoYan(intTemp) <> Right(sfID, 1) Then getCheckCode = "错误" | End Function | |
|