以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  【求助】自动编号问题  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=152672)

--  作者:宝宝猪jerry
--  发布时间:2020/7/18 4:52:00
--  【求助】自动编号问题
老师,

我认为语法和逻辑没问题呀,怎么会报错呢?

请问正确的代码应该怎么写才能得到  输入创建日期、客户编码和部门编码得到 :

客户编码(4位)-部门编号(2位)-年号(2位)-顺序号(2位)

弄了好久,实在着急,麻烦老师帮忙解决下,十分感激!



图片点击可在新窗口打开查看此主题相关图片如下:微信图片_20200718044710.png
图片点击可在新窗口打开查看

--  作者:有点蓝
--  发布时间:2020/7/18 9:21:00
--  
表达式里面有多余的双引号
--  作者:宝宝猪jerry
--  发布时间:2020/7/18 10:45:00
--  
老师,我反复测试了下,不知道多余再了那里,能具体告诉我吗?
谢谢

--  作者:有点蓝
--  发布时间:2020/7/18 10:47:00
--  
发代码,不要截图
--  作者:宝宝猪jerry
--  发布时间:2020/7/18 10:56:00
--  
问题1,不知道双引号多余在哪里?
问题2,我截取的是年的后2位,是不是后面的创建日期不需要这样写的?

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("客户编号") & "-" & e.DataRow("部门代号") & "-" & Format(d,"yy")        \'生成编号的前缀
            If e.DataRow("项目编号").StartsWith(bh) = False \'如果单据编号前缀不符
                Dim max As String
                Dim idx As Integer
                Dim flt As String
                flt = "客户编号 = \'" & e.DataRow("客户编号") & " \'And "部门代号 = \'" & e.DataRow("部门代号") & " \'And 创建日期 >= #" & fd & "# And 创建日期 <= #" & ld & "#  And [_Identify] <> " & e.DataRow("_Identify")
                max = e.DataTable.Compute("Max(项目编号)",flt)


--  作者:有点蓝
--  发布时间:2020/7/18 11:17:00
--  
自己弹出结果看看就知道了,另外要注意空格的位置

msgbox(flt)

--------
flt = "客户编号 = \'" & e.DataRow("客户编号") & "\' And 部门代号 = \'" & e.DataRow("部门代号") & "\' And 创建日期 >= #" & fd & "# And 创建日期 <= #" & ld & "#  And [_Identify] <> " & e.DataRow("_Identify")
--  作者:宝宝猪jerry
--  发布时间:2020/7/18 11:26:00
--  
问题1 了解了,谢谢

问题2 我截取的是年的后2位,是不是后面的创建日期不需要这样写的?

应该是怎么写的?

--  作者:有点蓝
--  发布时间:2020/7/18 11:36:00
--  
贴出完整代码
--  作者:宝宝猪jerry
--  发布时间:2020/7/18 11:55:00
--  
老师,

下面这段代码不出错了,但是自动编号的顺序号没有变化,请问是什么原因?

Select e.DataCol.Name
    Case "客户编号","部门代号"
        If e.DataRow.IsNull("客户编号") OrElse e.DataRow.IsNull("部门代号") Then
            e.DataRow("项目编号") = Nothing
        Else
            Dim dh As String = format(e.DataRow("创建日期"),"yy")
            Dim kh As String = e.DataRow("客户编号")
            Dim bb As String = e.DataRow("部门代号")
            Dim bh As String = kh & "-" & bb & "-" & dh        
            If e.DataRow("项目编号").StartsWith(bh) = False 
                Dim max As String
                Dim idx As Integer
                Dim flt As String
                flt = "客户编号 = \'" & kh & " \'And 部门代号 = \'" & bb & " \' And [_Identify] <> " & e.DataRow("_Identify")
                max = e.DataTable.Compute("Max(项目编号)",flt) 
                If max > "" Then \'如果存在最大单据编号
                    idx = CInt(max.Substring(9,2)) + 1 
                Else
                    idx = 1 
                End If
                e.DataRow("项目编号") = bh & Format(idx,"00")
            End If
        End If
End Select
--  作者:有点蓝
--  发布时间:2020/7/18 12:04:00
--  
注意空格的位置,请仔细认真看6楼。如果看不出来,使用命令窗口调试(http://www.foxtable.com/webhelp/topics/1485.htm),把2个结果使用output.show输出来然后一个一个字符对比较