以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助]自定义函数故障求解  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=24486)

--  作者:zcw2764
--  发布时间:2012/10/15 16:28:00
--  [求助]自定义函数故障求解

自定义功能权限函数,代码如下,用Functions.execute("功能权限","人力资源","职工信息","","") 调用时显示超出数组界限,不知原因何在,求高手指点
"

Dim str0 As String = args(0)
Dim str1 As String = args(1)
Dim str2 As String = args(2)
Dim str3 As String = args(3)
Dim str4 As String
Dim strs As New List(of String)
Dim dt As DataTable
Dim dr As DataRow
Dim cmd As new sqlcommand
cmd.ConnectionName = _DBSource1
If _UserID = "000" Then
    Return True
    Exit Function
End If
cmd.CommandText = "SELECT * From {系统_功能权限} where 功能权限分组 = \'管理员\'"
dt = cmd.ExecuteReader()
If dt.DataRows.count <> 0 Then
    For Each dr In dt.DataRows
        If dr.IsNull("功能权限用户") = False Then
            strs.AddRange(dr("功能权限用户").Split(","))
            If Strs.Contains(_UserID) = True Then
                Return True
                Exit Function
            End If
        End If
    Next
Else
    messagebox.show("未找到 [管理员] 功能权限分组或权限,请检查","提示")
    Return False
    Exit Function
End If
If str1 Is Nothing Then
    str4 = "功能权限分组 = \'" & str0 & "\' And 功能权限子组 is null And 功能权限名称 is null And 功能权限细分 is null"
ElseIf str2 Is Nothing Then
    str4 = "功能权限分组 = \'" & str0 & "\' And 功能权限子组 = \'" & str1 & "\' And 功能权限名称 is null And 功能权限细分 is null"
ElseIf str3 Is Nothing Then
    str4 = "功能权限分组 = \'" & str0 & "\' And 功能权限子组 = \'" & str1 & "\' And 功能权限名称 = \'" & str2 & "\' And 功能权限细分 Is null"
Else
    str4 = "功能权限分组 = \'" & str0 & "\' And 功能权限子组 = \'" & str1 & "\' And 功能权限名称 = \'" & str2 & "\' And 功能权限细分 = \'" & str3 & "\'"
End If
cmd.CommandText = "SELECT * From {系统_功能权限} where " & str4 & " "
dt = cmd.ExecuteReader()
If dt.DataRows.count = 1 Then
    dr = dt.DataRows(0)
    If dr.IsNull("功能权限用户") = False Then
        strs.AddRange(dr("功能权限用户").Split(","))
        If Strs.Contains(_UserID) = True Then
            Return True
        Else
            Return False
        End If
    Else
        Return False
    End If
Else
    messagebox.show("未找到[" & str0 & "] - [" & str1 & "] - [" & str2 & "] - [" & str3 & "] 功能权限设置,请检查","提示")
    Return False
End If


--  作者:狐狸爸爸
--  发布时间:2012/10/15 17:03:00
--  

做个例子发上来说话,否则别人很难帮你。

另外请先自己找出错误代码位置:

http://www.foxtable.com/help/topics/1485.htm

 


--  作者:lin_hailun
--  发布时间:2012/10/15 17:03:00
--  
 strs.AddRange(dr("功能权限用户").Split(","))

或者这句

 cmd.CommandText = "SELECT * From {系统_功能权限} where " & str4 & " "

------------------------------------------

楼主在代码里插入 msgbox 确定出错位置

http://www.foxtable.com/help/topics/1485.htm