Foxtable(狐表)用户栏目专家坐堂 → 用函数拆分程序代码


  共有2934人关注过本帖树形打印复制链接

主题:用函数拆分程序代码

帅哥哟,离线,有人找我吗?
有点蓝
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:107739 积分:548028 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2022/3/1 11:49:00 [显示全部帖子]

完整代码放到记事本发上来

 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:107739 积分:548028 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2022/3/1 14:02:00 [显示全部帖子]

方法1、比如下面代码
If xm="4121车间人员工资"
                wr("合计")=round2(tcjgz,2)
                mtgh1=DataTables("ddpsb").Compute("Sum(自产重量)","[发货日期]>= #" & dt5 & "# and [发货日期]<= #" & dt6 & "# and [客户]='" & nm & "'And substring([ddlb],1,1)='c'" & " and 发货日期 Is not null")  '分月层压木产量
                mtgh2=DataTables("ddpsb").Compute("Sum(自产重量)","[发货日期]>= #" & dt5 & "# and [发货日期]<= #" & dt6 & "# and [客户]='" & nm & "'And substring([ddlb],1,1)='z'" & " and 发货日期 Is not null")  '分月纸板产量
                mtgh=mtgh1+mtgh2
                mtzb1=mtgh1/mtgh
                mtzb2=mtgh2/mtgh
                
                mtcjgz0=DataTables("fyb").Compute("Sum(金额)","[日期]>= #" & dt5 & "# and [日期]<= #" & dt6 & "# and [二级代码]='a010'")   '车间工资
                mtcjgz1=mtcjgz0*mtzb1
                mtcjgz2=mtcjgz0*mtzb2
                mtcjgz=mtcjgz1+mtcjgz2
                wr(zd1)=round2(mtcjgz,2)
                
            End If

添加一个函数,假设名称为"4121车间人员工资"
Dim wr As DataRow = args(0)
Dim tcjgz As Double = args(1)
Dim dt5 As Date = args(3)
Dim dt6 As Date = args(4)
wr("合计")=round2(tcjgz,2)
Dim mtgh1=DataTables("ddpsb").Compute("Sum(自产重量)","[发货日期]>= #" & dt5 & "# and [发货日期]<= #" & dt6 & "# and [客户]='" & nm & "'And substring([ddlb],1,1)='c'" & " and 发货日期 Is not null")  '分月层压木产量
Dim mtgh2=DataTables("ddpsb").Compute("Sum(自产重量)","[发货日期]>= #" & dt5 & "# and [发货日期]<= #" & dt6 & "# and [客户]='" & nm & "'And substring([ddlb],1,1)='z'" & " and 发货日期 Is not null")  '分月纸板产量
mtgh=mtgh1+mtgh2
Dim mtzb1=mtgh1/mtgh
Dim mtzb2=mtgh2/mtgh

Dim mtcjgz0=DataTables("fyb").Compute("Sum(金额)","[日期]>= #" & dt5 & "# and [日期]<= #" & dt6 & "# and [二级代码]='a010'")   '车间工资
Dim mtcjgz1=mtcjgz0*mtzb1
Dim mtcjgz2=mtcjgz0*mtzb2
Dim mtcjgz=mtcjgz1+mtcjgz2
wr(zd1)=round2(mtcjgz,2)

然后上面蓝色代码就可以改为
If xm="4121车间人员工资"
    Functions.Execute("4121车间人员工资",wr,tcjgz,dt5 ,dt6)
End If

方法2、比如把1楼的代码全部放到一个函数里,可以把xm也作为参数传入,比如
Dim wr As DataRow = args(0)
Dim tcjgz As Double = args(1)
Dim dt5 As Date = args(3)
Dim dt6 As Date = args(4)
dim xm as string = args(5)
If xm="4121车间人员工资"
 wr("合计")=round2(tcjgz,2)
Dim mtgh1=DataTables("ddpsb").Compute("Sum(自产重量)","[发货日期]>= #" & dt5 & "# and [发货日期]<= #" & dt6 & "# and [客户]='" & nm & "'And substring([ddlb],1,1)='c'" & " and 发货日期 Is not null")  '分月层压木产量
Dim mtgh2=DataTables("ddpsb").Compute("Sum(自产重量)","[发货日期]>= #" & dt5 & "# and [发货日期]<= #" & dt6 & "# and [客户]='" & nm & "'And substring([ddlb],1,1)='z'" & " and 发货日期 Is not null")  '分月纸板产量
mtgh=mtgh1+mtgh2
Dim mtzb1=mtgh1/mtgh
Dim mtzb2=mtgh2/mtgh

Dim mtcjgz0=DataTables("fyb").Compute("Sum(金额)","[日期]>= #" & dt5 & "# and [日期]<= #" & dt6 & "# and [二级代码]='a010'")   '车间工资
Dim mtcjgz1=mtcjgz0*mtzb1
Dim mtcjgz2=mtcjgz0*mtzb2
Dim mtcjgz=mtcjgz1+mtcjgz2
wr(zd1)=round2(mtcjgz,2)
            End If
            If xm="4122车间人员社保"
                wr("合计")=round2(tsba,2)
                Dim mtgh1=DataTables("ddpsb").Compute("Sum(自产重量)","[发货日期]>= #" & dt5 & "# and [发货日期]<= #" & dt6 & "# and [客户]='" & nm & "'And substring([ddlb],1,1)='c'" & " and 发货日期 Is not null")  '分月层压木产量
                Dim mtgh2=DataTables("ddpsb").Compute("Sum(自产重量)","[发货日期]>= #" & dt5 & "# and [发货日期]<= #" & dt6 & "# and [客户]='" & nm & "'And substring([ddlb],1,1)='z'" & " and 发货日期 Is not null")  '分月纸板产量
                Dim mtgh=mtgh1+mtgh2
                Dim mtzb1=mtgh1/mtgh
                Dim mtzb2=mtgh2/mtgh
                Dim mtsba90=DataTables("fyb").Compute("Sum(金额)","[日期]>= #" & dt5 & "# and [日期]<= #" & dt6 & "# and [二级代码]='a090'")   '社保
                Dim mtsba91=DataTables("fyb").Compute("Sum(金额)","[日期]>= #" & dt5 & "# and [日期]<= #" & dt6 & "# and [二级代码]='a091'")   '社保
                
                Dim mtsba0=mtsba90+mtsba91  '社保
                Dim mtsba1=mtsba0*mtzb1
                Dim mtsba2=mtsba0*mtzb2
                Dim mtsba=mtsba1+mtsba2
                wr(zd1)=round2(mtsba,2)
            End If
……
……

调用方法,在原代码段里把1楼的代码改为下面即可
Functions.Execute("函数1",wr,tcjgz,dt5 ,dt6,xm)
[此贴子已经被作者于2022/3/1 14:01:58编辑过]

 回到顶部