vb身份证读取桌面程序

用VB编写的神思的身份证读取信息的桌面程序

主要实现了DLL文件的调用,二进制读取txt文件并转换出其中的中文。

桌面程序界面所有文件

Private Sub Command1_Click()
    Dim name$, sex$, nation$, birthday$, address$, IDNo$, organization$, startdate$, enddate$
    Picture1.Picture = LoadPicture("")
    nPortRet = InitCommExt()
    If (nPortRet = 0) Then
        Label10.Caption = "端口初始化失败" + Str(nPortRet)
    Else
        Label10.Caption = "端口初始化成功" + Str(nPortRet)
        nRet = Authenticate()
        If (nRet <> 1) Then
            Label10.Caption = "卡认证失败"
        Else
            Label10.Caption = "卡认证成功"
            nRet = Read_Content(1)
            If (nRet <> 1) Then
                Label10.Caption = "读卡失败"
            Else
                Label10.Caption = "读卡成功"
                nRet = GetBmpPhoto("xp.wlt")
                If (nRet <> 1) Then
                    Label10.Caption = "照片读取失败"
                Else
                    Dim DAT() As Byte
                    Dim FileSize As Long '文件长度
                    FileSize = FileLen(App.path & "\wz.txt") '获取文件长度
                    Open App.path & "\wz.txt" For Binary As #1
                    ReDim DAT(FileSize - 1) As Byte
                        Get #1, , DAT
                    Close
                    info = StrConv(StrConv(DAT, vbFromUnicode), vbUnicode)
                    Debug.Print info
                    name = Replace(Mid(info, 1, 15), " ", "")
                    sex = Mid(info, 16, 1)
                    nation = Mid(info, 17, 2)
                    birthday = Mid(info, 19, 4) & "/" & Mid(info, 23, 2) & "/" & Mid(info, 25, 2)
                    address = Replace(Mid(info, 27, 35), " ", "")
                    IDNo = Mid(info, 62, 18)
                    organization = Replace(Mid(info, 80, 15), " ", "")
                    startdate = Mid(info, 95, 4) & "/" & Mid(info, 99, 2) & "/" & Mid(info, 101, 2)
                    enddate = Mid(info, 103, 4) & "/" & Mid(info, 107, 2) & "/" & Mid(info, 109, 2)
                    Picture1.Picture = LoadPicture(App.path & "\zp.bmp")
                End If
            End If
        End If
    End If
    Text1.Text = name
    Text2.Text = TransSex(sex)
    Text3.Text = TransNation(nation)
    Text4.Text = birthday
    Text5.Text = address
    Text6.Text = IDNo
    Text7.Text = organization
    Text8.Text = startdate
    Text9.Text = enddate
End Sub
Private Function TransNation(nation As String) As String
    Select Case nation
    Case "01"
        TransNation = "汉"
    Case "02"
        Transnaeion = "蒙古"
    End Select
End Function

Private Function TransSex(sex As String) As String
    If (sex = "1") Then
        TransSex = "男"
    ElseIf (sex = "2") Then
        TransSex = "女"
    ElseIf (sex = "0") Then
        TransSex = "未知"
    ElseIf (sex = "9") Then
        TransSex = "未说明"
    End If
End Function


Private Sub Command2_Click()
nRet = CloseComm()
If (nRet = 1) Then
Label10.Caption = "关闭成功"
Else
Label10.Caption = "关闭失败"
End If
End Sub
Public Declare Function InitComm Lib "termb.dll" (ByVal nPort As Integer) As Integer

Public Declare Function InitCommExt Lib "termb.dll" () As Integer

Public Declare Function CloseComm Lib "termb.dll" () As Integer

Public Declare Function Authenticate Lib "termb.dll" () As Integer

Public Declare Function Read_Content Lib "termb.dll" (ByVal Active As Integer) As Integer

Public Declare Function GetSAMID Lib "termb.dll" (ByVal SAMID As String) As Integer

Public Declare Function GetBmpPhoto Lib "termb.dll" (ByVal path As String) As Integer

代码含义

猜你喜欢

转载自blog.csdn.net/shepherd_dirk/article/details/80395540