以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  请哪位高手帮忙看一下错在哪里?  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=43479)

--  作者:ap9709130
--  发布时间:2013/12/8 15:48:00
--  请哪位高手帮忙看一下错在哪里?

我想在订单明细里的产品批号能自动生成,订单明细里的订单日期设为当天。代码如下:

If e.DataCol.Name = "订单日期" Then
    If e.DataRow.IsNull("订单日期") Then
        e.DataRow("产品批号") = Nothing
    Else
        Dim bh As String = Format(e.DataRow("订单日期"),"yyyyMMdd") \'取得编号的8位前缀
        If e.DataRow("产品批号").StartsWith(bh) = False \'如果编号的前8位不符
            Dim max As String
            Dim idx As Integer
            max = e.DataTable.Compute("Max(产品批号)","订单日期 = #" & e.DataRow("订单日期") & "# And [_Identify] <> " & e.DataRow("_Identify")) \'取得该天的最大编号
            If max > "" Then \'如果存在最大编号
                idx = CInt(max.Substring(9,3)) + 1 \'获得最大编号的后三位顺序号,并加1
            Else
                idx = 1 \'否则顺序号等于1
            End If
            e.DataRow("产品批号") = bh & "-" & Format(idx,"000")
        End If
    End If
End If
我是在表的事件datacolschaned里设的以上代码?但运行不了。错误如下:.NET Framework 版本:2.0.50727.7905
Foxtable 版本:2013.10.14.1
错误所在事件:表,订单明细表,DataColChanged
详细错误信息:
调用的目标发生了异常。
startIndex 不能大于字符串长度。
参数名: startIndex
怎么也想不明白,我在其它表上用这个方法都行的,请高手指点一下!


--  作者:程兴刚
--  发布时间:2013/12/8 17:07:00
--  
If e.DataCol.Name = "订单日期" Then
    If e.DataRow.IsNull("订单日期") Then
        e.DataRow("产品批号") = Nothing
    Else
        Dim bh As String = Format(e.DataRow("订单日期"),"yyyyMMdd") \'取得编号的8位前缀
        If e.DataRow("产品批号").StartsWith(bh) = False \'如果编号的前8位不符
            Dim max As String
            Dim idx As Integer
            max = e.DataTable.Compute("Max(产品批号)","订单日期 = #" & e.DataRow("订单日期") & "# And [_Identify] <> " & e.DataRow("_Identify")) \'取得该天的最大编号
            If len(max) = 12 Then \'如果存在最大编号且编号长度正确
                idx = CInt(max.Substring(9,3)) + 1 \'获得最大编号的后三位顺序号,并加1
            Else
                idx = 1 \'否则顺序号等于1
            End If
            e.DataRow("产品批号") = bh & "-" & Format(idx,"000")
        End If
    End If
End If