專題裡應該可以拿來用....
順便測試剛剛替blogspot加的code碼有沒有成功....
Private Sub Command1_Click()
Dim S As String
IDChk Text1.Text, S
MsgBox S
End Sub
Function IDChk(ByVal ID As String, Optional ByRef msg As String = "") As Boolean
Dim A As Integer, B As Integer, C As Integer, S As String
ID = UCase(ID): S = Left(ID, 1): IDChk = False
If Len(ID) <> 10 Then msg = "身份證必須是 十碼!": Exit Function
If (S < "A" Or S > "Z") Then msg = "身份證第 一碼 必須是英文字母!": Exit Function
If Mid(ID, 2, 1) <> "1" And Mid(ID, 2, 1) <> "2" Then msg = "身分證第 二碼 只能是數字 1(男) 或 2(女)!": Exit Function
If Not IsNumeric(Mid(ID, 3)) Then msg = "身分證第 三碼 至第 十碼 不是全部為數字!": Exit Function
A = InStr("ABCDEFGHJKLMNPQRSTUVXYWZIO", S) + 9
ID = CStr(A) & Mid(ID, 2)
B = CInt(Mid(ID, 1, 1)) + CInt(Mid(ID, 11, 1))
For C = 2 To 10
B = B + CInt(Mid(ID, C, 1)) * (11 - C)
Next C
If (B Mod 10 = 0) Then
IDChk = True: msg = "身分證正確!!"
Else
msg = "身分證輸入錯誤,請再檢查!"
End If
End Function
沒有留言:
張貼留言