我在SQL Reporting Services中使用此自定义代码.问题是它永远不会达到假的条件.如果条件不为真,则函数不会返回"false".当值为True(打印"X")时它工作正常,否则我得到#Error.
我正在从文本框中调用该函数:
= IIF(Code.CodeExist(Variables!MyCode.Value) = true, "X", "")
function CodeExist( ByVal Codigo As String) as Boolean
dim i as integer
dim Centinela as integer
i = 0
Centinela = 0
for i = 0 To Report.Parameters!CodeList.Count()
if Report.Parameters!CodeList.Value(i) = Codigo Then
Centinela = 1
Exit For
End If
Next
If Centinela = 1 Then
Return true
Else
Return false // IT NEVERS RETURN FALSE even if Centinela = 0
End If
End function
Run Code Online (Sandbox Code Playgroud)
我不知道发生了什么.提前致谢.
VBA没有"退货"声明.要返回您使用的值(例如)
....
If Centinela = 1 Then
CodeExist = True
Else
CodeExist = False
End If
End Function
Run Code Online (Sandbox Code Playgroud)
或者(更整洁):
....
CodeExist = (Centinela = 1)
End Function
Run Code Online (Sandbox Code Playgroud)