一个条码枪扫描的程序,请各位帮帮忙!重谢!!!

bin889 2003-10-20 10:39:56
我正在做一个条码枪扫描的程序,条码枪接的是计算机的键盘口,扫描后条码会自然显示在文本里(当然这时你要打开一个文本),但我对键盘监控的函数不太熟,如果用程序做时,不知道怎么控制,例如我怎么才能知道他扫入到文本框里了等等,请各位帮帮忙!  最好是哪位做过这类程序,告诉我他当时怎么做的!
...全文
317 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
tccth4091 2003-10-24
  • 打赏
  • 举报
回复
不用这样,超市的来说吧,一用商品就是一种的条码,加上数量就可以了。
sharkliang 2003-10-24
  • 打赏
  • 举报
回复
关注!!!!
golden24kcn 2003-10-24
  • 打赏
  • 举报
回复
给你点代码

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 Sub

Private Sub tmr_Timer()
Dim I As Integer

tmr.Enabled = False
If Id = "" Then Exit Sub

For 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
Next

Dim Rst As ADODB.Recordset
Dim CRst As ADODB.Recordset
Dim SQL As String
Dim SumCash As Currency

SQL = "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 Sub

SQL = "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 = Nothing

Grid.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 = Nothing

IDList.Add Id

ee:

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")

Id = ""

End Sub
饮水需思源 2003-10-24
  • 打赏
  • 举报
回复
键盘接口的扫描枪不用写代码,就像手工在键盘输入一样操作
golden24kcn 2003-10-24
  • 打赏
  • 举报
回复
不用这样的,你可以在keyup 或者keydown里设置,如果vbkeyf3(就是F3)就把焦点给到别一个文本框,你可以在这里修改数量,默认是1,在这里敲回车后,那么就代表确认了数量,把焦点再给到扫描条码的文本框.

我一般都是用flexgrid来接收条码,条码枪不设置加回车,我用timer来读,(timer设置的时间很短).这样每输入一个条码,自动增加一行记录,(名称/数量/单位/合计/打折/实际应收)如果按了f3就可以更改数量,F4更改打折,等等.

不过以上只是我个人的思路,楼上各位老大与我观点不同的地方我认为也很有道理.
Lionking1027 2003-10-24
  • 打赏
  • 举报
回复
UP
coldboy 2003-10-24
  • 打赏
  • 举报
回复
请问超市里的商品条码是如何管理的,是否每一单件商品的条码都要录入数据库中?
举个例子:
飘柔 10盒,是否每一件飘柔的条码都要录入进去。
各位能否给个关于条码录入的完整例子程序。谢谢!
zxlkxy 2003-10-23
  • 打赏
  • 举报
回复
对,就是键盘输入,只是在最后加了一个回车。你检测到有回车的时候,就扫描出来了。
jinxjun 2003-10-23
  • 打赏
  • 举报
回复
不用其它DLL,条码枪其实就是键盘输入,只要程序具有文本输入焦点就行!!
zjsxyanghua 2003-10-21
  • 打赏
  • 举报
回复
条码枪帮你输了回车,其他的都一样。不需要DLL,也不需要别的控件
佛的光辉 2003-10-20
  • 打赏
  • 举报
回复
就如同一楼的一样,你的条码枪对于程序来说就像键盘一样,一般条码枪会配置成一个条码扫完后送一个回车。
flc 2003-10-20
  • 打赏
  • 举报
回复
用COMM控件吗?
kmzs 2003-10-20
  • 打赏
  • 举报
回复
用什么dll?
subzero 2003-10-20
  • 打赏
  • 举报
回复
只能是要扫描时,把焦点定在文本框,没什么技巧
一把扫描枪可以设置返回字符串带不带vbcrlf
我们的做法是
sub textbox_keypress()
if ascii=13 then
if textbox.text 是合法条码 then
处理条码
end if
end if
end sub

1,485

社区成员

发帖
与我相关
我的任务
社区描述
VB API
社区管理员
  • API
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧