我在SSRS报告中有一些自定义代码,当我使用Excel VBA中的测试数据运行它时,它可以很好地工作(有微小的变化),但在SSRS中失败并出现错误
文本框'textbox72'的值表达式包含错误:对象引用未设置为对象的实例
该报告是一份简单的表格报告。自定义代码比较审计报告中的“之前”和“之后”字符串,并应发回添加或删除的详细信息。字符串由char(10)分隔。只能添加或删除字符串行。字符串行本身不会改变。没有空字符串。我已经在Excel VBA中成功测试了这个,所以我认为代码可能没问题。有什么想法吗?
textbox72中的代码调用是
=iif(len(Fields!AOS.Value) > 0 and len(Fields!AfterAOS.Value) > 0,code.go_compare(ReportItems),"")
报告中的代码是:
Function go_compare(Items as ReportItems) as string
Dim j As Integer
Dim x As Integer
Dim Diff(50) As String
Dim DiffInd As Integer
Dim Intmatch As Integer
Dim StrDiff as string
Dim Arr() As String
Dim Arr1() As String
Dim StrVal As String
Dim StrFinal As String
Dim y As Integer
Dim Str1 as string
Dim Str2 as string
Str1 = items("AOS_1").value
Str2 = items("AfterAOS").value
StrFinal = ""
StrDiff = ""
For y = 0 To 1
Erase Diff
If y = 1 Then
StrVal = "Removed"
Arr = Split(Str1, Chr(10))
Arr1 = Split(Str2, Chr(10))
Else
StrVal = "Added"
Arr = Split(Str2, Chr(10))
Arr1 = Split(Str1, Chr(10))
End If
For j = 0 To UBound(Arr)
Intmatch = 0
For x = 0 To UBound(Arr1)
If Trim(Arr(j)) = Trim(Arr1(x)) Then
Intmatch = 1
End If
Next x
If Intmatch = 0 Then
Diff(DiffInd) = Trim(Arr(j))
DiffInd = DiffInd + 1
End If
Next j
StrDiff = StrDiff & StrVal & " Values" + vbCrLf
For j = 0 To UBound(Diff)
If Diff(j) = "" Then Exit For
StrDiff = StrDiff + Diff(j) + vbCrLf
Next j
If Len(StrDiff) > 16 Then
StrFinal = StrFinal + StrDiff
End If
StrDiff = ""
Next y
Return StrFinal
End Function
示例数据(来自Excel VBA测试)
Dim StrStr1 As String
Dim StrStr2 As String
StrStr1 = "xxxx" & Chr(10)
StrStr1 = StrStr1 & "yyyy" & Chr(10)
StrStr1 = StrStr1 & "zzzz" & Chr(10)
StrStr1 = StrStr1 & "aaaa" & Chr(10)
StrStr1 = StrStr1 & "bbbb" & Chr(10)
StrStr1 = StrStr1 & "cccc" & Chr(10)
StrStr1 = StrStr1 & "dddd" & Chr(10)
StrStr2 = "xxxx" & Chr(10)
StrStr2 = StrStr2 & "yyyy" & Chr(10)
StrStr2 = StrStr2 & "zzzz" & Chr(10)
StrStr2 = StrStr2 & "aaaa" & Chr(10)
StrStr2 = StrStr2 & "bbbb" & Chr(10)
StrStr2 = StrStr2 & "dddd" & Chr(10)
StrStr2 = StrStr2 & "eeee" & Chr(10)
预期结果
Removed Values
cccc
Added Values
eeee
答案 0 :(得分:0)
问题似乎来自Erase Diff语句。如果我用数组的ReDim跟随它,那么例程就可以了!
那里的任何人都知道为什么原始代码(即没有ReDim)可以在Excel VBA中工作但在SSRS中不工作?
For y = 0 To 1
Erase Diff
Redim Diff(100)