以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  [求助]从字符串“******”到类型“Boolean”的转换无效。  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=121687)

--  作者:狐说八道
--  发布时间:2018/7/11 16:52:00
--  [求助]从字符串“******”到类型“Boolean”的转换无效。
如题,代码如下:
For x As Integer = 2 To 12
    For Each r As Row In tb.Rows
        cl = sheet(x,0).value
        lx = sheet(x,2).value
        ys = sheet(x,3).value
        If cl <> "" Then
            filter = "r(""材料"") = """ & cl & """"
        End If
        If lx <> "" Then
            filter = filter & " AndAlso r(""类型"") = """ & lx & """"
        End If
        If ys <> "" Then
            filter = filter & " AndAlso r(""钥匙"").contains(""" & ys & """)"
        End If
        filter = filter.TrimStart(" ","A","n","d","l","s","o")
        If filter Then
        \'If r("材料") = cl AndAlso r("类型") = lx AndAlso r("钥匙").contains(ys) Then
            For i As Integer = 4 To tb.Cols.Count -1
                If r.Isnull(i) = False Then
                    If sheet(x,i+2).value <> "" Then
                        sheet(x,i+2).value = sheet(x,i+2).value + r(i)
                    Else
                        sheet(x,i+2).value = r(i)
                    End If
                End If
            Next
        End If
    Next
Next

老师,我想根据cl,lx,ys是否是空值来控制if的条件,请问该怎么改??

--  作者:有点甜
--  发布时间:2018/7/11 17:08:00
--  

方法一:

 


For x As Integer = 2 To 12
    For Each r As Row In tb.Rows
        cl = sheet(x,0).value
        lx = sheet(x,2).value
        ys = sheet(x,3).value
        Dim flag As Boolean = True
        If cl <> "" Then
            flag = flag AndAlso (r("材料") = cl)
        End If
        If lx <> "" Then
            flag = flag AndAlso (r("类型") = lx)
        End If
        If ys <> "" Then
            flag = flag AndAlso (r("钥匙").contains(ys))
        End If
        If flag Then
            \'If r("材料") = cl AndAlso r("类型") = lx AndAlso r("钥匙").contains(ys) Then
            For i As Integer = 4 To tb.Cols.Count -1
                If r.Isnull(i) = False Then
                    If sheet(x,i+2).value <> "" Then
                        sheet(x,i+2).value = sheet(x,i+2).value + r(i)
                    Else
                        sheet(x,i+2).value = r(i)
                    End If
                End If
            Next
        End If
    Next
Next


--  作者:有点甜
--  发布时间:2018/7/11 17:09:00
--  

方法二:动态编译执行字符串代码

 

http://www.foxtable.com/webhelp/scr/1487.htm

 


--  作者:狐说八道
--  发布时间:2018/7/11 17:14:00
--  
我试试,谢谢甜老师