以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  错误信息判断  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=94161)

--  作者:luckbetter333
--  发布时间:2016/12/17 8:15:00
--  错误信息判断
我借鉴“常用的编号生成方法”编程,提示下述错误,请问是哪里出了问题,应该怎么修改?

Select e.DataCol.Name
    Case "制单时间","生产车间"
        If e.DataRow.IsNull("制单时间") OrElse e.DataRow.IsNull("生产车间") Then
            e.DataRow("产品批号") = Nothing
        Else
            Dim d As Date = e.DataRow("制单时间")
            Dim y As Integer = d.Year
            Dim m As Integer = d.Month
            Dim Days As Integer = Date.DaysInMonth(y,m)
            Dim fd As Date = New Date(y,m,1) \'获得该月的第一天
            Dim ld As Date = New Date(y,m,Days) \'获得该月的最后一天
            Dim bh As String = e.DataRow("生产车间") & "-" & Format(d,"yyyyMM") & "-" \'生成编号的前缀
            If e.DataRow("产品批号").StartsWith(bh) = False \'如果单据编号前缀不符
                Dim max As String
                Dim idx As Integer
                Dim flt As String
                flt = "生产车间 = \'"& e.DataRow("生产车间") & "\' And 制单时间 >= #" & fd & "# And 制单时间 <= #" & ld & "# And [_Identify] <> " & e.DataRow("_Identify")
                max = e.DataTable.Compute("Max(产品批号)",flt) \'取得该月的相同工程代码的最大单据编号
                If max > "" Then \'如果存在最大单据编号
                    idx = CInt(max.Substring(12,4)) + 1 \'获得最大单据编号的后四位顺序号,并加1
                Else
                    idx = 1 \'否则顺序号等于1
                End If
                e.DataRow("产品批号") = bh & Format(idx,"0000")
            End If
        End If
End Select


错误所在事件:表,生产计划,DataColChanged
详细错误信息:
调用的目标发生了异常。
索引和长度必须引用该字符串内的位置。
参数名: length



--  作者:狐狸爸爸
--  发布时间:2016/12/17 9:15:00
--  
一般是这行出错,你长度计算方面有问题,或者原来的编号不规范:

idx = CInt(max.Substring(12,4)) + 1 \'获得最大单据编号的后四位顺序号,并加1

你可以试试改为:

idx = CInt(max.Substring(max.Length-4,4)) + 1



--  作者:luckbetter333
--  发布时间:2016/12/17 9:53:00
--  
明白了含义,把前面的字符改成一个长度的,数字改成9就好了,不过-4不可以的,字符数字不可以为负数。谢谢狐爸!