2009年1月30日 星期五

麗山50題之15

image

image 

image 

 image

Public Class Form1
    Function checkid(ByVal perID As String) As Boolean
        Dim engarray As String
        Dim peridtemp As Integer
        Dim peridchk1, peridchk2, peridchksum As Integer
        Dim loops As Integer
        engarray = "ABCDFGHJKLMNPQRSTUVXYWZIO"
        peridtemp = InStr(1, engarray, Microsoft.VisualBasic.Left(perID, 1)) + 9
        peridchk1 = (peridtemp \ 10) + (peridtemp Mod 10) * 9
        For loops = 2 To 9
            peridchk2 = peridchk2 + Val(Mid(perID, loops, 1)) * (10 - loops)
        Next
        peridchksum = Val(Microsoft.VisualBasic.Right(perID, 1))
        If (peridchk1 + peridchk2 + peridchksum) Mod 10 = 0 Then
            checkid = True
        Else
            checkid = False
        End If
    End Function
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Len(TextBox1.Text) = 10 Then
            If checkid(UCase(TextBox1.Text)) Then
                Label2.Text = "這是一個正確的身分證號碼"
            Else
                Label2.Text = "這是一個錯誤的身分證號碼"
            End If
        Else
            Label2.Text = "身分證號碼需要10碼"
            TextBox1.Text = ""
        End If
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        End
    End Sub
End Class

1 則留言: