以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  if 语句总提示“应为语句结束”  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=22752)

--  作者:zpx_2012
--  发布时间:2012/8/22 23:08:00
--  if 语句总提示“应为语句结束”

各位老师,下面的语句哪里有问题,确定时总提示“应为语句结束”

If _UserName <> "开发者" Then
        For Each dr1 As DataRow In DataTables("授权表").Select("部门 = \'" & _UserGroup & "\' And 角色 In (\'" & _UserRole & "\')")
            If dr1.IsNull("可查看列") Then
                Tables(dr1("表名")).Visible = False
                Tables(dr1("表名")).AllowEdit = False
            ElseIf dr1.IsNull("可编辑列") Then
                Tables(dr1("表名")).AllowEdit = False
            Else
                For Each c As Col In dr1("表名").Cols
                    If c.name In (dr1("可查看列")) Then
                        c.Visible = True
                    ElseIf c.name In dr1(("可编辑列")) Then
                        c.AllowEdit = True
                    End If
                Next
            End If
        Next
 End If


 


此主题相关图片如下:qq截图20120822230601.jpg
按此在新窗口浏览图片

--  作者:woiz
--  发布时间:2012/8/22 23:47:00
--  

if c.name in dr1("可查看列") then

 

去掉 ()试一下


--  作者:woiz
--  发布时间:2012/8/22 23:47:00
--  
去掉外面的()
--  作者:woiz
--  发布时间:2012/8/22 23:48:00
--  

ElseIf c.name In dr1(("可编辑列")) Then
这句好像也应该为:

 

ElseIf c.name In dr1("可编辑列") Then


--  作者:zpx_2012
--  发布时间:2012/8/23 0:35:00
--  

谢谢各位的回复,还是不行,可能不能用"in"做判断,后来只好把代码改成下面,麻烦了一些,但是可以了,跟大家分享一下,不知道狐爸有什么好办法?

If _UserName <> "开发者" Then
        For Each dr1 As DataRow In DataTables("授权表").Select("部门 = \'" & _UserGroup & "\' And 角色 In (\'" & _UserRole & "\')")
            If dr1.IsNull("可查看列") Then
                Tables(dr1("表名")).Visible = False
                Tables(dr1("表名")).AllowEdit = False
            ElseIf dr1.IsNull("可编辑列") Then
                Tables(dr1("表名")).AllowEdit = False
            Else
                For Each tb As Table In Tables
                    If tb.name = dr1("表名") Then
                        For Each c As Col In tb.Cols
                            Dim a As String = c.name
                            If dr1("可查看列").contains(a) Then
                                c.Visible = True
                            ElseIf dr1("可编辑列").contains(a) Then
                                c.AllowEdit = True
                            Else
                                c.Visible = False
                                c.AllowEdit = False
                            End If
                        Next
                    End If
                Next
            End If
        Next
    End If


--  作者:blackzhu
--  发布时间:2012/8/23 7:50:00
--  

if c.name in dr1("可查看列") then   行吗?没有试过  没有这样的写法的吧.


--  作者:jspta
--  发布时间:2012/8/23 9:07:00
--  

For Each c As Col In dr1("表名").Cols
dr是datarow,表示行,没有cols属性的吧

 

for each ...in..

 

next

这整个是一个语句,in不是一个语句,你搞错了

[此贴子已经被作者于2012-8-23 9:13:08编辑过]

--  作者:woiz
--  发布时间:2012/8/23 11:11:00
--  

现在才明白你的意思

不是 in 语句不能用,而是你在用的时候,语法错误了

 

你的dr1("表名")中应该是一个字符串吧,存放各个col名

 

in 的用法是:

if  col.name in (\'xxx1\',\'xxx2\',\'xxx3\'....)

 

所以如果你要用 in 的话,应该对dr1("表名")进行一下转换,转换成  (\'xxx1\',\'xxx2\',\'xxx3\'....)才可以

 

因此,直接用string的contains方便一点