以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 循环语句问题 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=135318) |
-- 作者:edisontsui -- 发布时间:2019/5/23 15:05:00 -- 循环语句问题 If User.Group = "行政" Or User.name = "开发者" If CurrentTable.name.contains("模具保养") For Each r As Row In Tables("生产模数统计").rows Dim NY As String = r("年") & r("月") If NY.length = 5 NY = r("年") & "0" & r("月") Else NY = r("年") & r("月") End If If r("模具型号") = "" Else For Each dr As DataRow In DataTables("模具保养").DataRows If dr("年月") = NY And dr("模具型号") = r("模具型号") dr("本月生产") = r("生产模数") Exit For End If Next End If Next End If End If 以上为原代码是可以正常运行的,但是,如果“模具保养”没有的“模具型号”而“生产模数统计”有的“模具型号”则不会自动添加到“模具保养”这个数据表去。 =========================== 我改成如下代码,但是运行起来会有问题:“模具保养”有的“模具型号”而且“生产模数统计”也有的“模具型号”,会自动再添加一次到“模具保养”这个数据表去。请帮我修改一下下面的代码,谢谢。 If User.Group = "行政" Or User.name = "开发者" If CurrentTable.name.contains("模具保养") For Each r As Row In Tables("生产模数统计").rows Dim NY As String = r("年") & r("月") If NY.length = 5 NY = r("年") & "0" & r("月") Else NY = r("年") & r("月") End If If r("模具型号") = "" Else For Each dr As DataRow In DataTables("模具保养").DataRows If dr("年月") = NY if dr("模具型号") = r("模具型号") dr("本月生产") = r("生产模数") Exit For else Dim dr1 As DataRow dr1 = DataTables("模具保养").AddNew() dr1("模具型号") = r("模具型号") dr1("本月生产") = r("生产模数") Exit For End If end if Next End If Next End If End If
|
-- 作者:有点甜 -- 发布时间:2019/5/23 16:39:00 -- If User.Group = "行政" Or User.name = "开发者" If CurrentTable.name.contains("模具保养") For Each r As Row In Tables("生产模数统计").rows Dim NY As String = r("年") & r("月") If NY.length = 5 NY = r("年") & "0" & r("月") Else NY = r("年") & r("月") End If If r("模具型号") = "" Else Dim contains As Boolean = False For Each dr As DataRow In DataTables("模具保养").DataRows If dr("年月") = NY If dr("模具型号") = r("模具型号") dr("本月生产") = r("生产模数") contains = True Exit For End If End If Next If contains = False Then Dim dr1 As DataRow dr1 = DataTables("模具保养").AddNew() dr1("模具型号") = r("模具型号") dr1("本月生产") = r("生产模数") End If End If Next End If End If |