以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  索引和长度必须引用该字符串内的位置  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=95689)

--  作者:bluev
--  发布时间:2017/2/1 11:28: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 = Format(d,"yyyyMM") &  e.DataRow("生产线")  \'生成编号的前缀
            If e.DataRow("生产记录号").StartsWith(bh) = False \'如果单据编号前缀不符
                Dim max As String
                Dim idx As Integer
                Dim flt As String
                flt = " 日期 >= #" & fd & "# And 日期 <= #" & ld & "# And 生产线 = \'"& e.DataRow("生产线") & "\' And [_Identify] <> " & e.DataRow("_Identify")
                max = e.DataTable.Compute("Max(生产记录号)",flt) \'取得该月的相同工程代码的最大单据编号
                If max > "" Then \'如果存在最大单据编号
MessageBox.Show(max)
                    idx = CInt(max.Substring(12,4)) + 1 \'获得最大单据编号的后四位顺序号,并加1
MessageBox.Show(2)
                Else
                    idx = 1 \'否则顺序号等于1
                End If
                e.DataRow("生产记录号") = bh & Format(idx,"0000")
            End If
        End If
End Select

其中    idx = CInt(max.Substring(13,4)) + 1 \'获得最大单据编号的后四位顺序号,并加1  在这句总是出现错误

idx = CInt(max.Substring(13,4)) + 1  为13 时错误提示
.NET Framework 版本:2.0.50727.8745
Foxtable 版本:2016.7.29.1
错误所在事件:表,生产记录,DataColChanged
详细错误信息:
调用的目标发生了异常。
startIndex 不能大于字符串长度。
参数名: startIndex
idx = CInt(max.Substring(12,4)) + 1  为12 时错误提示
.NET Framework 版本:2.0.50727.8745
Foxtable 版本:2016.7.29.1
错误所在事件:表,生产记录,DataColChanged
详细错误信息:
调用的目标发生了异常。
索引和长度必须引用该字符串内的位置。
参数名: length
这是什么问题?

--  作者:有点色
--  发布时间:2017/2/2 10:01:00
--  

改成

 

idx = CInt(max.Substring(bh.length)) + 1