以文本方式查看主题

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

--  作者:edisontsui
--  发布时间:2017/12/1 11:03:00
--  自动输入日期问题

下面这段代码,到了12月份的今天,就无法自动输入日期列了,请问代码错在哪里?谢谢!




If e.DataCol.Name = "票号"

    If e.DataRow("票号") Is Nothing

    Else

        Dim dr As DataRow = e.DataRow

        If e.DataRow("票号").Length = 10

            e.DataRow("票号") = "0" & e.DataRow("票号")

        End If

        Dim da As String

        Dim d1 As Date = Date.today

        If d1.Month = 12

            If dr("票号").StartsWith("01")

                da = d1.year + 1"-" & dr("票号").Substring( 0, 2) & "-" & dr("票号").Substring( 2, 2)

            End If

        Else

            da = d1.year &  "-" & dr("票号").Substring( 0, 2) & "-" & dr("票号").Substring( 2, 2)

            dr("日期") = Cdate(da)

        End If

      dr("工位") = dr("票号").substring(4,3

    End If

End If


--  作者:有点甜
--  发布时间:2017/12/1 11:46:00
--  

试试改成

 

        If d1.Month = 12

            If dr("票号").StartsWith("01")

                da = d1.year + 1 &  "-" & dr("票号").Substring( 0, 2) & "-" & dr("票号").Substring( 2, 2)

msgbox(da)

dr("日期") = Cdate(da)

            End If

        Else

            da = d1.year &  "-" & dr("票号").Substring( 0, 2) & "-" & dr("票号").Substring( 2, 2)

            dr("日期") = Cdate(da)

        End If


--  作者:edisontsui
--  发布时间:2017/12/1 12:23:00
--  
还是不行,日期列还是不能自动输入。
--  作者:有点蓝
--  发布时间:2017/12/1 14:51:00
--  
dr("票号")存储的是什么数据?
--  作者:有点甜
--  发布时间:2017/12/1 15:09:00
--  
       If d1.Month = 12

            da = d1.year + 1 &  "-" & dr("票号").Substring( 0, 2) & "-" & dr("票号").Substring( 2, 2)

msgbox(da)

dr("日期") = Cdate(da)

        Else

            da = d1.year &  "-" & dr("票号").Substring( 0, 2) & "-" & dr("票号").Substring( 2, 2)

            dr("日期") = Cdate(da)

        End If


--  作者:edisontsui
--  发布时间:2017/12/1 15:57:00
--  
我另外找到原因了,下述代码就可以:

        If d1.Month = 12
            If dr("票号").StartsWith("01")
                da = d1.year + 1 &  "-" & dr("票号").Substring( 0, 2) & "-" & dr("票号").Substring( 2, 2)
                dr("日期") = Cdate(da)
            Else
                da = d1.year &  "-" & dr("票号").Substring( 0, 2) & "-" & dr("票号").Substring( 2, 2)
                dr("日期") = Cdate(da)
            End If
        Else
            da = d1.year &  "-" & dr("票号").Substring( 0, 2) & "-" & dr("票号").Substring( 2, 2)
            dr("日期") = Cdate(da)
        End If