以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 用函数拆分程序代码 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=175325) |
||||
-- 作者:朱女士 -- 发布时间: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 |
||||
-- 作者:有点蓝 -- 发布时间:2022/3/1 11:49:00 -- 完整代码放到记事本发上来 |
||||
-- 作者:朱女士 -- 发布时间:2022/3/1 12:11:00 --
|
||||
-- 作者:有点蓝 -- 发布时间: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 -- 发布时间:2022/3/1 14:04:00 -- 感觉做成EXCEL的形式了 |