我想打出一各身分證的格式 就是(身分證格式為十碼 , 第一碼為英文字母後9位數字若不符合此規定在標示位\"格式錯誤\")
學校作業~~麻煩幫幫忙
2006-03-21 15:39:37 · 1 個解答 · 發問者 吳冠 1 in 電腦與網際網路 ➔ 程式設計
Private Sub Command1_Click() MsgBox IDChk(Text1.Text)End SubFunction IDChk(ByVal ID As String) As String Dim A As Integer, B As Integer, C As Integer, S As String IDChk = "格式錯誤!!" ID = UCase(ID): S = Left(ID, 1) '身份證必須是十碼! If Len(ID) <> 10 Then Exit Function '身份證第一碼必須是英文字母 If (S < "A" Or S > "Z") Then Exit Function '身分證第二碼只能是數字 1(男) 或 2(女) If Mid(ID, 2, 1) <> "1" And Mid(ID, 2, 1) <> "2" Then Exit Function '身分證第三碼至第十碼必須是數字 If Not IsNumeric(Mid(ID, 3)) Then 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 Exit Function IDChk = "身分證正確!!"End Function
2006-03-22 08:07:27 · answer #1 · answered by W.J.S. 7 · 0⤊ 0⤋