以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助]代码耗时问题  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=123855)

--  作者:81538475
--  发布时间:2018/8/24 18:39:00
--  [求助]代码耗时问题
      为啥下面这个代码耗时需要0.9秒之久
可以如何优化呢 

       Dim sum2 As Double
        sum2 = DataTables("XMFP").Compute("Sum(当月人天)","BH =  \'" & e.DataRow("BH") & "\' ")
        Dim dr As DataRow = DataTables("xmzb").find("BH = \'" & E.DataRow("bh") & "\'")

        Dim st As Date = Date.Now

        dr("剩余") = dr("apc") - sum2
        dr("总") = dr("apc") - dr("剩余")

        MessageBox.Show("耗时: " & (Date.Now - st).TotalSeconds & "秒")


--  作者:新福星
--  发布时间:2018/8/24 20:03:00
--  
 Dim sum2 As Double
        sum2 = DataTables("XMFP").Compute("Sum(当月人天)","BH =  \'" & e.DataRow("BH") & "\' ")
        Dim dr As DataRow = DataTables("xmzb").find("BH = \'" & E.DataRow("bh") & "\'")

        Dim st As Date = Date.Now
if dr isnot nothing then
        dr("剩余") = dr("apc") - sum2
        dr("总") = dr("apc") - dr("剩余")
end if
 MessageBox.Show("耗时: " & (Date.Now - st).TotalSeconds & "秒")
看不出优化的可能,其中需要做Sum运算费时间,这个和你的记录数多少相关.但是若想无错运行,需要加入红笔代码

--  作者:81538475
--  发布时间:2018/8/24 20:20:00
--  
多谢
--  作者:有点蓝
--  发布时间:2018/8/24 20:30:00
--  
如果是赋值耗时,一般是触发了其他事件,或者表达式的计算