以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  多条件代码怎么简洁  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=172018)

--  作者:wangglby
--  发布时间:2021/9/18 11:31:00
--  多条件代码怎么简洁

这样的代码怎么简洁写,

checkbox1,2,3 的值 排列组合,可以是任意一种组合方式,执行的代码相应的变化

 

 

if forms("窗口1").controls("checkbox1").checked =true   and   forms("窗口1").controls("checkbox2").checked =false and   forms("窗口1").controls("checkbox3").checked =false   then

dim dr as list(of datarow)= datatables("表A").select("第列 =         ") 

end if

if forms("窗口1").controls("checkbox1").checked =false   and   forms("窗口1").controls("checkbox2").checked =true  and   forms("窗口1").controls("checkbox3").checked =false   then 

dim dr as list(of datarow)= datatables("表A").select("第列 =         ")  

end if

if forms("窗口1").controls("checkbox1").checked =true  and   forms("窗口1").controls("checkbox2").checked =true  and   forms("窗口1").controls("checkbox3").checked =false   then 

dim dr as list(of datarow)= datatables("表A").select("第列 =    and    第列 =         ")  

end if

f forms("窗口1").controls("checkbox1").checked =true  and   forms("窗口1").controls("checkbox2").checked =true  and   forms("窗口1").controls("checkbox3").checked =TRUE   then 

dim dr as list(of datarow)= datatables("表A").select("第列 =    and    第列 =  and   第列 =       ")  

end if

.

.

.


--  作者:有点蓝
--  发布时间:2021/9/18 11:42:00
--  
dim s as string = ""
for i as integer = 1 to 3 
s = s & IIF(forms("窗口1").controls("checkbox" & i).checked,"1","0")
next

select case s
case "001"

case "010"
……

--  作者:y2287958
--  发布时间:2021/9/18 12:00:00
--  
Dim dic As New Dictionary(Of object, String)
dic.add(forms("窗口13").controls("checkbox1"),"第一列 =         ")
dic.add(forms("窗口13").controls("checkbox2"),"第二列 =         ")
dic.add(forms("窗口13").controls("checkbox3"),"第三列 =         ")
Dim lst As new List(of String)
For Each k As object In dic.Keys
    If k.checked = True Then lst.add(dic(k))
Next
Output.Show(String.join(" and ",lst))

--  作者:有点蓝
--  发布时间:2021/9/18 12:03:00
--  
可能是我理解错了,参考这种:http://www.foxtable.com/webhelp/topics/1058.htm
--  作者:chnfo
--  发布时间:2021/9/18 14:00:00
--  
Dim css As String = "第一列,第二列,第三列"
Dim cs As String() = css.Split(",")

Dim s As String = ""
For i As Integer = 1 To 3
    If forms("窗口1").controls("checkbox" & i).checked Then
        s &= cs(i-1) & "= \'xx\' and "  
    End If 
Next
 
Dim drs As List(of DataRow) = DataTables("表A").Select(s.trim("a","n","d"," "))