以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  求助 自动编号 错误提示  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=20681)

--  作者:yifan3429
--  发布时间:2012/6/15 17:56:00
--  求助 自动编号 错误提示

Select e.DataCol.Name
    Case "日期","类别"
        If 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,"yyyyMMdd") & "-" \'生成编号的前缀
            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 & "#"
                max = e.DataTable.Compute("Max(订单编号)",flt) \'取得该月的相同工程代码的最大单据编号
                If max > "" Then \'如果存在最大单据编号
                    idx = CInt(max.Substring(12,3)) + 1 \'获得最大单据编号的后四位顺序号,并加1
                Else
                    idx = 1 \'否则顺序号等于1
                End If
                e.DataRow("订单编号") = bh & Format(idx,"000")
            End If
        End If
End Select

 

列设置  订单编号  字付型   20

            类别       字符型    20

 

 

 

 

错误提示如下:

---------------------------
版本:2012.6.3.1
---------------------------
错误代码位置:表,原材料,DataColChanged

 

System.ArgumentOutOfRangeException: startIndex 不能大于字符串长度。

参数名: startIndex

   在 System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy)

   在 UserCode.DataColChanged(DataColEventArgs e)
---------------------------
确定  
---------------------------

请问是哪里出了问题

 


--  作者:狐狸爸爸
--  发布时间:2012/6/15 18:03:00
--  

问题可能出在这里:

 

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

 

好好看看:

 

http://www.foxtable.com/help/topics/2403.htm

 


--  作者:ksyh518
--  发布时间:2012/6/15 18:54:00
--  自动编号错误

呵呵:请看一下

   1、Dim bh As String = e.DataRow("类别") & Format(d,"yyyyMMdd") & "-" \'生成编号的前缀
   2、idx = CInt(max.Substring(12,3)) + 1 \'获得最大单据编号的后四位顺序号,并加1

 

第1条中的编号前缀的字符数与第2条中的12个字符不相等了哈,

注:(12,3)应改为(类别4位、日期8位、一个“-”,就是13位了。