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


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

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

美女呀,离线,留言给我吧!
朱女士
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:一尾狐 帖子:453 积分:3683 威望:0 精华:0 注册:2020/2/8 11:14:00
用函数拆分程序代码  发帖心情 Post By:2022/3/1 11:19:00 [只看该作者]

老师您好!
     还是昨天的问题,由于代码编辑器里的程序过长,光标和滑块不锁定的问题。我看了一下您发得帮助链接,仍然没弄明白怎么用函数拆分程序代码。例如:以下代码怎么拆分?谢谢指点!
 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
            If xm="4122车间人员社保"
                wr("合计")=round2(tsba,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
                mtsba90=DataTables("fyb").Compute("Sum(金额)","[日期]>= #" & dt5 & "# and [日期]<= #" & dt6 & "# and [二级代码]='a090'")   '社保
                mtsba91=DataTables("fyb").Compute("Sum(金额)","[日期]>= #" & dt5 & "# and [日期]<= #" & dt6 & "# and [二级代码]='a091'")   '社保
                
                mtsba0=mtsba90+mtsba91  '社保
                mtsba1=mtsba0*mtzb1
                mtsba2=mtsba0*mtzb2
                mtsba=mtsba1+mtsba2
                wr(zd1)=round2(mtsba,2)
            End If
            If xm="4123固定资产折旧"
                wr("合计")=round2(tzj,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
                
                mtzj0=DataTables("fyb").Compute("Sum(金额)","[日期]>= #" & dt5 & "# and [日期]<= #" & dt6 & "# and [二级代码]='a110'")   '折旧
                mtzj1=mtzj0*mtzb1
                mtzj2=mtzj0*mtzb2
                mtzj=mtzj1+mtzj2
                wr(zd1)=round2(mtzj,2)
            End If
            If xm="4124设备维修维护"
                wr("合计")=round2(twhf,2)
                mtwhf0=DataTables("fyb").Compute("Sum(金额)","[日期]>= #" & dt5 & "# and [日期]<= #" & dt6 & "# and [二级代码]='a050'")   '设备维护费
                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
                mtwhf1=mtwhf0*mtzb1
                mtwhf2=mtwhf0*mtzb2
                mtwhf=mtwhf1+mtwhf2
                wr(zd1)=round2(mtwhf,2)
            End If
            If xm="4125税金"
                wr("合计")=round2(tsj,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
                mtsj0=DataTables("fyb").Compute("Sum(金额)","[日期]>= #" & dt5 & "# and [日期]<= #" & dt6 & "# and [二级代码]='a100'")   '税金
                mtsj1=mtsj0*mtzb1
                mtsj2=mtsj0*mtzb2
                mtsj=mtsj1+mtsj2
                wr(zd1)=round2(mtsj,2)
            End If
            If xm="4126易耗工具及材料"
                wr("合计")=round2(tyhf,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
                
                mtyhf0=DataTables("fyb").Compute("Sum(金额)","[日期]>= #" & dt5 & "# and [日期]<= #" & dt6 & "# and [二级代码]='a030'")  '易耗材料工具
                mtyhf1=mtyhf0*mtzb1
                mtyhf2=mtyhf0*mtzb2
                mtyhf=mtyhf1+mtyhf2
                wr(zd1)=round2(mtyhf,2)
                
            End If


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


加好友 发短信
等级:超级版主 帖子:107718 积分:547917 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2022/3/1 11:49:00 [只看该作者]

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

 回到顶部
美女呀,离线,留言给我吧!
朱女士
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:一尾狐 帖子:453 积分:3683 威望:0 精华:0 注册:2020/2/8 11:14:00
  发帖心情 Post By:2022/3/1 12:11:00 [只看该作者]

 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:程序.txt


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


加好友 发短信
等级:超级版主 帖子:107718 积分:547917 威望: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编辑过]

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


加好友 发短信
等级:童狐 帖子:223 积分:2218 威望:0 精华:0 注册:2016/10/9 16:10:00
  发帖心情 Post By:2022/3/1 14:04:00 [只看该作者]

感觉做成EXCEL的形式了

 回到顶部