自动编号不会递增?
Dim bh As String = "采购" & "-"
Dim max As String
Dim idx As Integer
Dim flt As String
flt = "[采购单号] Like '采购%'" & "And [_Identify] <> " & e.DataRow("_Identify")
If max > "" Then
idx = CInt(max.Substring(3, 4)) + 1
Else
idx = 1
End If
e.DataRow("采购单号") = bh & Format(idx, "0000")
Dim bh As String = "采购" & "-"
Dim max As String
Dim idx As Integer
Dim flt As String
flt = "[采购单号] Like '采购%'" & "And [_Identify] <> " & e.DataRow("_Identify")
max = e.DataTable.Compute("Max(采购单号)", flt)
If max > "" Then
idx = CInt(max.Substring(3, 4)) + 1
Else
idx = 1
End If
e.DataRow("采购单号") = bh & Format(idx, "0000")
调试
……
max = e.DataTable.Compute("Max(采购单号)", flt)
msgbox(max )
If max > "" Then
idx = CInt(max.Substring(3, 4)) + 1
Else
idx = 1
End If
msgbox(idx )
.NET Framework 版本:4.0.30319.42000
Foxtable 版本:2022.8.18.1
错误所在事件:表,物资采购,DataRowAdded
详细错误信息:
调用的目标发生了异常。
索引和长度必须引用该字符串内的位置。
参数名: length
idx = CInt(max.Substring(3, 4)) + 1改成 idx = CInt(max.Substring(3) + 1
已解决
max = e.DataTable.Compute("Max(采购单号)", flt)
msgbox(max )
编号有 采购-05和采购-0006,找到的最大值为什么是采购-05?
字符串是从左到右逐个字符比较的,第5个字符5比0大:采购-0
5和采购-0
006
编号最好是有规律的,格式一致,不然很难处理
[此贴子已经被作者于2023/11/1 9:17:52编辑过]
蓝老师,标记部分读不懂,帮我解释一下,谢谢e.DataRow("顺序号") = Format(e.DataTable.Compute("Count(采购单号)", "[采购单号] = '" & e.DataRow("采购单号") & "' And [_identify] < 0" & (e.DataRow("_Identify")) + 1) , "000")