以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  如果前缀的位数不固定应该怎么办?(name的位数)  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=87070)

--  作者:jinzhengbe
--  发布时间:2016/7/2 11:09:00
--  如果前缀的位数不固定应该怎么办?(name的位数)
Select e.DataCol.Name
    Case "name"
        If e.DataRow.IsNull("name") Then
            e.DataRow("lei2") = Nothing
        Else
            Dim lb As String = e.DataRow("name")
            If e.DataRow("lei2").StartsWith(lb) = False \'如果单据lei2前缀不符
                Dim max As String
                Dim idx As Integer
                max = e.DataTable.Compute("Max(lei2)","name = \'" & lb & "\' And [_Identify] <> " & e.DataRow("_Identify")) \'取得该类别的最大lei2
                If max > "" Then \'如果存在最大lei2
                    idx = CInt(max.Substring(2,3)) + 1 \'获得最大lei2的后三位顺序号,并加1
                Else
                    idx = 1 \'否则顺序号等于1
                End If
                e.DataRow("lei2") = lb & Format(idx,"000")
            End If
        End If
End Select

这个代码 如果 name的位数不是固定的 应该怎么改?
因为是商品名 每个名字的位数都不是固定的。

麻烦各位大师指点一下

--  作者:Hyphen
--  发布时间:2016/7/2 11:23:00
--  
idx = CInt(max.Substring(max.Length-3,3)) + 1 \'获得最大lei2的后三位顺序号,并加1