我软件接收盘点枪的代码这样写:
Forms("盘点").Controls("TextBox1").Text = Forms("盘点").Controls("TextBox1").Text & e.Port.ReadExisting()
我从textbox1合并到表格的数据是这样:

此主题相关图片如下:微信截图_20171127200211.png


此主题相关图片如下:微信截图_20171127200222.png

代码这样写:
Dim max As String
Dim idx As Integer
max = Forms("盘点").Controls("table1").Table.DataTable.Compute("Max(库位)") '取得该月的最大编号
If max >= 1 Then '如果存在最大编号
idx = max + 1
Else
idx = 1 '否则顺序号等于1
End If
Dim strs As String = forms("盘点").Controls("textbox1").value
Dim xm As String = strs.SubString(0,1)
strs = strs.Replace(vblf,"")
Dim rs() As String = strs.Split(xm)
For i As Integer = 0 To rs.Length - 1
Dim cs() As String = rs(i).Split(xm)
If cs.Length = 1 Then
Dim dr As DataRow = DataTables("盘点").Addnew()
dr("门店名称") = _username
dr("盘点日期") = Date.Today
dr("条码") = cs(0)
dr("盘点枪编号") = xm
dr("库位") = Format(idx,"0000")
dr("上传时间") =Date.now
If dr("条码") IsNot "" Then
dr("数量") = 1
Else
dr("条码") = "本库位合计"
End If
End If
Next
然后导出的代码这样写:
Dim str As String = ""
Dim t As Table = Tables("盘点")
For Each r As Row In t.Rows
If r("条码") <> "本库位合计" Then
For Each c As Col In t.cols
If c.name = "库位" Or c.name = "条码" Or c.name = "数量" Then
str &= r(c) & ","
End If
Next
str = str.Trim(",") & vbcrlf
'str = str.Replace(vblf,"")
End If
Next
Dim pd As String = "\pd" & Date.now.Hour & Date.now.Minute & Date.now.Second & ".txt"
FileSys.WriteAllText(SpecialFolder.DesktopDirectory & pd, str, False, encoding.default)

此主题相关图片如下:微信截图_20171127204051.png

现在只要把,1移到上一行的末尾就可以导入到ERP系统里了。。。
不知道怎么会出现这个问题
[此贴子已经被作者于2017/11/27 20:48:07编辑过]