我现在用的刷卡机我键盘是同一根线,
在程序中用一个文本框接收刷卡或键盘输入,我现在不知道怎样处理这个事件(刷卡转换数据,卡数据长短不一),那位能告诉我可以在文本框的那个事件中处理,刷卡是否相当于只按了键盘中的一次键

解决方案 »

  1.   

    刷卡就是一个输入过程,相当于你手工输入了一串字符
    你可以使用Textbox的onchange事件来捕获有的刷卡机器会默认做一次回车触发的,这个就需要看具体的卡机功能了。onchange和KeyPress分别试验一下即可
      

  2.   

    1
    Private Sub txt_Change(Index As Integer)
        Static ok As Boolean
        Select Case Index
            Case 8          '归/借还读卡时
                If Len(txt(8).Text) >= 11 Then
                    txt(8).SelStart = 0
                    txt(8).SelLength = Len(txt(8).Text)
                End If
                If right$(txt(8).Text, 1) = ";" _
                    Or right$(txt(8).Text, 1) = "?" Then
                    If Len(txt(8).Text) = 1 Then
                        txt(8).Text = ""
                    Else
                        txt(8).Text = Mid(txt(8).Text, 1, Len(txt(8).Text) - 1)
                    End If
                End If
        End Select
    End Sub
    2
    Private Sub txt_KeyPress(Index As Integer, KeyAscii As Integer)
        Select Case Index       '刷卡
            Case 8
                If KeyAscii = 13 Then
                    DoEvents
                    Dim myOperation As New clsOperation         '业务处理类
                    If myOperation.ValidateCard(txt(8).Text) = False Then
                        MsgBox myOperation.strError, vbOKOnly + vbInformation, "警告"
                        cboEmp(5).Text = ""
                        Exit Sub
                    Else
                        strSql = SEL_EMP & " where role_id=" & Purpose.Worker
                        strSql = strSql & " and user_id=" & myOperation.UserID
                        Set aRst(5) = ExecuteSQL(strSql)
                        Set cboEmp(5).DataSource = aRst(5)
                        cboEmp(5).DataField = "user_id"
                    End If
                End If
        End Select
    End Sub就是在Change和KeyPress里处理.
    一般读卡器都会在最后一位打个回车出来的.
      

  3.   

    没有回车?
    卡号长度总是固定的吧?你用记事本打开一下,看看刷上去的都是什么.
    然后跟据位长在Change事件中去掉无用的字符.
      

  4.   

    长度也不是固定的,能否在keyup事件中处理?
      

  5.   

    长度也不是固定的,能否在keyup事件中处理?应该可以吧.你再讲讲情况,是刷什么卡?卡号长度不固定?