测试210724840618401 预期结果应该为21072419840618401X 而得到的结果却为2107248406184010
如果让pos+1 却得到了正确的9
测试210724880606402 结果为210724198806064025 正确
测试210724800626401 结果210724198006264010 正确
Private Sub Command1_Click()
Dim num1 As Variant
Dim w As Variant
Dim code As Variant
Dim s As Integer
Dim pos As Integer
Dim i As Integer
s = 0
num1 = Text1.Text
w = Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2) '给权重表赋值
code = Array(1, 0, X, 9, 8, 7, 6, 5, 4, 3, 2) '给校验表赋值
If Len(num1) = 15 Then
num1 = Left(num1, 6) + "19" + Right(num1, 9) '添加数字19
For i = 1 To 17
s = s + (w(i - 1)) * (Val(Mid(num1, i, 1))) '累加求和(测试例子结果299正确)
Next
pos = s Mod 11 '求模 (模得2正确)
num1 = num1 + Trim(Str(code(pos))) '加上校验码(应该取X却取不出来)
text2.Text = num1
Else
MsgBox "请您输入原15位身份证号码"
End If
End Sub