我正在做一个条码枪扫描的程序,条码枪接的是计算机的键盘口,扫描后条码会自然显示在文本里(当然这时你要打开一个文本),但我对键盘监控的函数不太熟,如果用程序做时,不知道怎么控制,例如我怎么才能知道他扫入到文本框里了等等,请各位帮帮忙!  最好是哪位做过这类程序,告诉我他当时怎么做的!

解决方案 »

  1.   

    只能是要扫描时,把焦点定在文本框,没什么技巧
    一把扫描枪可以设置返回字符串带不带vbcrlf
    我们的做法是
    sub textbox_keypress()
    if ascii=13 then
      if textbox.text 是合法条码 then
        处理条码
      end if
    end if
    end sub
      

  2.   

    条码枪帮你输了回车,其他的都一样。不需要DLL,也不需要别的控件
      

  3.   

    不用其它DLL,条码枪其实就是键盘输入,只要程序具有文本输入焦点就行!!
      

  4.   

    不用这样的,你可以在keyup 或者keydown里设置,如果vbkeyf3(就是F3)就把焦点给到别一个文本框,你可以在这里修改数量,默认是1,在这里敲回车后,那么就代表确认了数量,把焦点再给到扫描条码的文本框.我一般都是用flexgrid来接收条码,条码枪不设置加回车,我用timer来读,(timer设置的时间很短).这样每输入一个条码,自动增加一行记录,(名称/数量/单位/合计/打折/实际应收)如果按了f3就可以更改数量,F4更改打折,等等.不过以上只是我个人的思路,楼上各位老大与我观点不同的地方我认为也很有道理.
      

  5.   

    给你点代码Private Sub Grid_KeyUp(KeyCode As Integer, Shift As Integer)
    Dim Rst As ADODB.Recordset
    Dim Cmd As ADODB.Command
    Dim SQL As String
    Dim I As Integer
    Dim N As Integer
          
      Select Case KeyCode
        Case vbKeyReturn
          If Grid.Rows <= 1 Then Exit Sub
          Dim K As Boolean
          K = Foot(lblSum.Caption, lblsums.Caption)
          If K = False Then Exit Sub
                
          Conn.BeginTrans
          
          Set Cmd = New ADODB.Command
          Cmd.ActiveConnection = Conn
          
          SQL = "insert into sell_index values ('" & lbl.Caption & "','" _
            & Format(Date$, "yyyy-mm-dd") & "','" & Format(Time$, "hh:mm:ss") & "','" & _
            UserName & "'," & lblSum.Caption & "," & txtZ.Text & "," & lblsums.Caption & ")"
          Cmd.CommandText = SQL
          Cmd.CommandType = adCmdText
          Cmd.Execute
      
          For I = 1 To Grid.Rows - 1
            SQL = "execute selling  '" & lbl.Caption & "','" & Grid.TextMatrix(I, 1) & "'," _
                & Grid.TextMatrix(I, 6) & "," & Grid.TextMatrix(I, 8) & "," _
                & Grid.TextMatrix(I, 9) & ",'" & Grid.TextMatrix(I, 5) & "'," & Grid.TextMatrix(I, 7)
            Cmd.CommandText = SQL
            Cmd.CommandType = adCmdText
            Cmd.Execute
          Next
          
          Conn.CommitTrans
          
          Call ReSet
          Number = Number + 1
          lbl.Caption = Format(Date$, "yymmdd") & "#" & Format(CStr(Number), "0000")
        Case vbKeyF3
          Call ReSet
        Case vbKeyF4
          If Grid.Rows = 1 Then Exit Sub
          txtNum.Top = Grid.Top + Grid.RowHeight(Grid.RowSel) * Grid.RowSel + 5
          txtNum.Visible = True
          txtNum.SetFocus
          txtNum.Text = Grid.TextMatrix(Grid.RowSel, 7)
          txtNum.SelStart = 0
          txtNum.SelLength = Len(txtNum.Text)
          Grid.Enabled = False
        Case vbKeyF5
          If Grid.Rows = 1 Then Exit Sub
          txtZK.Top = Grid.Top + Grid.RowHeight(Grid.RowSel) * Grid.RowSel + 5
          txtZK.Visible = True
          txtZK.SetFocus
          txtZK.Text = Grid.TextMatrix(Grid.RowSel, 8)
          txtZK.SelStart = 0
          txtZK.SelLength = Len(txtZK.Text)
          Grid.Enabled = False
        Case vbKeyF6
          fra.Visible = True
          Grid.Enabled = False
          txtTM.SetFocus
        Case vbKeyF7
          ''单位
          If Grid.Rows = 1 Then Exit Sub
          
          
          Set Rst = New ADODB.Recordset
          SQL = "select unit from yaopin_unit where id='" & Grid.TextMatrix(Grid.RowSel, 1) & "'"
          Rst.Open SQL, Conn, adOpenStatic, adLockReadOnly, adCmdText
          If Rst.EOF Then Exit Sub
          
          cobUnit.Clear
          For I = 1 To Rst.RecordCount
            cobUnit.AddItem Rst.Fields(0)
            Rst.MoveNext
          Next
          Set Rst = Nothing
          cobUnit.Top = Grid.Top + Grid.RowHeight(Grid.RowSel) * Grid.RowSel + 5
          cobUnit.Visible = True
          cobUnit.SetFocus
          Grid.Enabled = False
        Case vbKeyF8
          If Grid.Rows = 1 Then Exit Sub
          txtZ.Enabled = True
          txtZ.SelStart = 0
          txtZ.SelLength = Len(txtZ.Text)
          txtZ.SetFocus
          Grid.Enabled = False
        Case vbKeyF9
          If Grid.Rows > 1 Then Exit Sub
          frmBack.Show 1
        Case vbKeyDelete, vbKeyBack
          Dim SumCash As Currency
          
          If Grid.RowSel = 0 Then Exit Sub
          If Grid.Rows = 2 Then ReSet: Exit Sub
          IDList.Remove Grid.RowSel
          Grid.RemoveItem Grid.RowSel
          For I = 1 To Grid.Rows - 1
            SumCash = SumCash + Val(Grid.TextMatrix(I, 10))
          Next
          lblSum.Caption = Format(CStr(SumCash), ".00")
          lblsums.Caption = Format(CStr(SumCash) * IIf(Val(txtZ.Text) = 1, 1, Val(txtZ.Text) / 10), ".00")
          
          For I = 1 To Grid.Rows - 1
            Grid.TextMatrix(I, 0) = CStr(I)
          Next
          
      End Select
    End SubPrivate Sub tmr_Timer()
    Dim I As Integertmr.Enabled = False
    If Id = "" Then Exit SubFor I = 1 To IDList.Count
      If Id = IDList(I) Then
        Grid.TextMatrix(I, 7) = CStr(Val(Grid.TextMatrix(I, 7)) + 1)
        Grid.TextMatrix(I, 10) = Format(CStr(Val(Grid.TextMatrix(I, 7)) * Grid.TextMatrix(I, 9)), ".00")
        GoTo ee
      End If
    NextDim Rst As ADODB.Recordset
    Dim CRst As ADODB.Recordset
    Dim SQL As String
    Dim SumCash As CurrencySQL = "select id,name,guige,changjia,unit,price from v_yaopin_list where tiaoma='" & Id & "' order by switch desc"
    Set Rst = New ADODB.Recordset
    Rst.CursorLocation = adUseClient
    Rst.Open SQL, Conn, adOpenStatic, adLockReadOnly, adCmdText
    If Rst.EOF Then Id = "": Exit SubSQL = "select * from yaopin_cost where id='" & Rst.Fields("id") & "'"
    Set CRst = New ADODB.Recordset
    CRst.CursorLocation = adUseClient
    CRst.Open SQL, Conn, adOpenDynamic, adLockReadOnly, adCmdText
    If CRst.EOF Then Exit Sub
    Set CRst = NothingGrid.Rows = Grid.Rows + 1
    Grid.TextMatrix(Grid.Rows - 1, 0) = Grid.Rows - 1
    Grid.TextMatrix(Grid.Rows - 1, 1) = Rst.Fields("id")
    Grid.TextMatrix(Grid.Rows - 1, 2) = Rst.Fields("name")
    Grid.TextMatrix(Grid.Rows - 1, 3) = Rst.Fields("guige")
    Grid.TextMatrix(Grid.Rows - 1, 4) = Rst.Fields("changjia")
    Grid.TextMatrix(Grid.Rows - 1, 5) = Rst.Fields("unit")
    Grid.TextMatrix(Grid.Rows - 1, 6) = Format(Rst.Fields("price"), ".00")
    Grid.TextMatrix(Grid.Rows - 1, 7) = "1"
    Grid.TextMatrix(Grid.Rows - 1, 8) = "1"
    Grid.TextMatrix(Grid.Rows - 1, 9) = Format(Rst.Fields("price"), ".00")
    Grid.TextMatrix(Grid.Rows - 1, 10) = Format(Rst.Fields("price"), ".00")Rst.Close
    Set Rst = NothingIDList.Add Idee:For I = 1 To Grid.Rows - 1
      SumCash = SumCash + Val(Grid.TextMatrix(I, 10))
    NextlblSum.Caption = Format(CStr(SumCash), ".00")
    lblsums.Caption = Format(CStr(SumCash) * IIf(Val(txtZ.Text) = 1, 1, Val(txtZ.Text) / 10), ".00")Id = ""End Sub