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里处理. 一般读卡器都会在最后一位打个回车出来的.
你可以使用Textbox的onchange事件来捕获有的刷卡机器会默认做一次回车触发的,这个就需要看具体的卡机功能了。onchange和KeyPress分别试验一下即可
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里处理.
一般读卡器都会在最后一位打个回车出来的.
卡号长度总是固定的吧?你用记事本打开一下,看看刷上去的都是什么.
然后跟据位长在Change事件中去掉无用的字符.