您可能會喜歡......

2019年5月18日 星期六

11800-1060306



Public Class Form1

    Dim d(100, 4)
    Dim rno As Integer
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        rdata()
        For i = 1 To rno
            If d(i, 4) = "" Then sp1(i)
            If d(i, 4) = "" Then sp2(i)
            If d(i, 4) = "" Then sp3(i)
        Next
        wdata()
    End Sub

    Sub rdata()
        FileOpen(1, "C:\940306.sm", OpenMode.Input)
        rno = 0
        Do While Not EOF(1)
            rno += 1
            Input(1, d(rno, 1)) : Input(1, d(rno, 2)) : Input(1, d(rno, 3))
        Loop
        FileClose()
    End Sub

    Sub sp1(ByVal i)
        Dim id = d(i, 1)
        If id Like "[A-Z]#########" Then  Else d(i, 4) = "FORMAT ERROR"
    End Sub

    Sub sp2(ByVal i)
        Dim D1S = Mid(d(i, 1), 2, 1) & d(i, 3)
        If (D1S = "1M") Or (D1S = "2F") Then  Else d(i, 4) = "SEX CODE ERROR"
    End Sub

    Sub sp3(ByVal i)
        Dim s26 = "ABCDEFGHJKLMNPQRSTUVXYWZIO"
        Dim L1 = Mid(d(i, 1), 1, 1)
        Dim X12 = InStr(s26, L1) + 9
        Dim x1 = X12 \ 10
        Dim x2 = X12 Mod 10

        Dim D1 = Mid(d(i, 1), 2, 1)
        Dim D2 = Mid(d(i, 1), 3, 1)
        Dim D3 = Mid(d(i, 1), 4, 1)
        Dim D4 = Mid(d(i, 1), 5, 1)
        Dim D5 = Mid(d(i, 1), 6, 1)
        Dim D6 = Mid(d(i, 1), 7, 1)
        Dim D7 = Mid(d(i, 1), 8, 1)
        Dim D8 = Mid(d(i, 1), 9, 1)
        Dim D9 = Mid(d(i, 1), 10, 1)

        Dim y = x1 + 9 * x2 + 8 * D1 + 7 * D2 + 6 * D3 + 5 * D4 + 4 * D5 + 3 * D6 + 2 * D7 + D8 + D9

        If y Mod 10 = 0 Then  Else d(i, 4) = "CHECK SUM ERROR"
    End Sub

    Sub wdata()
        DGV.columns.add("ID NO", "ID NO")
        DGV.Columns.Add("NAME", "NAME")
        DGV.Columns.Add("SEX", "SEX")
        DGV.Columns.Add("ERROR", "ERROR")

        For i = 1 To rno
            DGV.Rows.Add(d(i, 1), d(i, 2), d(i, 3), d(i, 4))
        Next

        DGV.Sort(DGV.Columns(0), System.ComponentModel.ListSortDirection.Ascending)
        DGV.Columns(2).Width = 50
        DGV.Columns(3).Width = 150
        DGV.AllowUserToAddRows = False
    End Sub
End Class

沒有留言:

張貼留言