以文本方式查看主题

-  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=184869)

--  作者:cnsjroom
--  发布时间:2023/1/11 19:14:00
--  生成编码 提示索引和长度必须引用该字符串内的位置

详细错误信息:
调用的目标发生了异常。
索引和长度必须引用该字符串内的位置。
参数名: length

 

当前代码如下:【编码格式52272220230001   52272220230002……】

Select Case e.DataCol.Name
    Case "录入日期"
        Dim d As Date = e.DataRow("录入日期")
        Dim r1 As DataRow =DataTables("代码表").Find("名称=\'卷宗编号前缀\'")
        If r1 IsNot Nothing  Then
            Dim bh As String = r1("代码") & Format(d,"yyyy")
            MessageBox.Show(bh)
            If e.DataRow("卷宗编号").StartsWith(bh) = False \'如果案件卷宗编号前缀不符
                Dim max As String
                Dim idx As Integer
                Dim flt As String
                flt = "[_Identify] <> " & e.DataRow("_Identify")
                max = e.DataTable.sqlCompute("Max(卷宗编号)",flt) \'取得该月的相同工程代码的最大案件卷宗编号
                If max > "" Then \'如果存在最大案件卷宗编号
                    idx = CInt(max.Substring(10,4)) + 1 \'获得最大案件卷宗编号的后四位顺序号,并加1
                Else
                    idx = 1 \'否则顺序号等于1
                End If
                e.DataRow("卷宗编号") = bh & Format(idx,"0000")
            End If
        Else
            MessageBox.Show("没有对应的卷宗编号前缀数据,请联系管理员")
        End If
End Select


--  作者:有点蓝
--  发布时间:2023/1/12 9:36:00
--  
idx = CInt(max.Substring(10,4)) + 1 
改为
idx = CInt(max.Substring(max.length - 4)) + 1