以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- 关于排列组合问题 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=185405) |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
-- 作者:YDS -- 发布时间:2023/2/21 15:08:00 -- 关于排列组合问题
\'上面表的排列组合代码如下: Dim t1 As Date = Date.Now Dim dt As DataTable = DataTables("表A") Dim l1s As List(Of String) = dt.GetValues("列1", "列1 Is Not Null") Dim l2s As List(Of String) = dt.GetValues("列2", "列2 Is Not Null") Dim l3s As List(Of String) = dt.GetValues("列3", "列3 Is Not Null") dim jh as string For Each l1 As String In l1s For Each l2 As String In l2s For Each l3 As String In l3s jh = l1 & l2 & l3 Next Next Next ‘现在的问题是如果不确定有多少符合条件的列时代码如何写,如下表
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
-- 作者:有点蓝 -- 发布时间:2023/2/21 15:50:00 -- Dim lst As new List(Of String) Dim l1s As List(Of String) = dt.GetValues("列1", "列1 Is Not Null") Dim l2s As List(Of String) = dt.GetValues("列2", "列2 Is Not Null") if l2s.count > 0 for each s1 as string in l1s for each s2 as string in l2s lst.add(s1 & s2) next next l1s.clear l1s.addrange(lst) lst.clear end if Dim l3s As List(Of String) = dt.GetValues("列3", "列3 Is Not Null") if l3s.count > 0 for each s1 as string in l1s for each s3 as string in l3s lst.add(s1 & s3) next next next if l1s.count > 0 andalso lst.count = 0 then lst.addrange(l1s) end if for each s as string in lst output.show(s) next |