網路城邦
上一篇 回創作列表 下一篇   字體:
身分證檢查
2009/12/11 12:04:20瀏覽525|回應0|推薦4

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim idno, L1, err, na, SEX As String
        Dim X1, X2, checkL1, D(9), Y, K As Integer

        FileOpen(1, "c:/940306.sm", OpenMode.Input)
        K = 0
        Do While Not EOF(1)
            Input(1, idno) : Input(1, na) : Input(1, SEX)

            err = ""

            If Len(idno) <> 10 Then
                err = "FORMAT ERROR"
            End If

            If err = "" Then
                L1 = Mid(idno, 1, 1)
                If L1 < "A" Or L1 > "Z" Then
                    err = "FORMAT ERROR"
                End If
            End If

            If err = "" Then
                For i = 2 To 10
                    If Mid(idno, i, 1) < "0" Or Mid(idno, i, 1) > "9" Then
                        err = "FORMAT ERROR"
                    End If
                Next
            End If

            If err = "" Then
                If Not (Mid(idno, 2, 1) = "1" And SEX = "M") And Not (Mid(idno, 2, 1) = "2" And SEX = "F") Then
                    err = "SEX CODE ERROR"
                End If
            End If

            If err = "" Then
                checkL1 = InStr("ABCDEFGHJKLMNPQRSTUVXYWZIO", L1) + 9

                X1 = Mid(checkL1, 1, 1)
                X2 = Mid(checkL1, 2, 1)


                For i = 1 To 9
                    D(i) = Mid(idno, i + 1, 1)
                Next

                Y = X1 + 9 * X2 + 8 * D(1) + 7 * D(2) + 6 * D(3) + 5 * D(4) + 4 * D(5) + 3 * D(6) + 2 * D(7) + D(8) + D(9)
                If Y Mod 10 <> 0 Then
                    err = "CHECK SUM ERROR"
                End If
            End If
            With DataGridView1
                .Rows.Add(1)
                .Item(0, K).Value = idno
                .Item(1, K).Value = na
                .Item(2, K).Value = SEX
                .Item(3, K).Value = err
                .Height = K * 35
                .Sort(Column1, System.ComponentModel.ListSortDirection.Ascending)
            End With
            K = K + 1
        Loop
        Me.Height = 150 + K * 35
        FileClose()
    End Sub

( 心情隨筆心情日記 )
回應 推薦文章 列印 加入我的文摘
上一篇 回創作列表 下一篇

引用
引用網址:https://classic-blog.udn.com/article/trackback.jsp?uid=ghost4011&aid=3578412