【问题标题】:Error after I inserted custom code in SSRS在 SSRS 中插入自定义代码后出错
【发布时间】:2016-08-10 15:59:05
【问题描述】:

在我的 SSRS 报告中插入自定义代码后,出现以下错误:

An error occurred during local report processing. The definition of the report ...in invalid. An unexpected error occured while compiling expressions. Native compiler return valid '[BC42105]' Function 'ColorDWB' doesn't return a value on all code paths. A null reference exception could occur at a run time when the result is used.

我要做的就是创建一个基于颜色深浅的​​ Excel 类热图。 我的自定义代码:

      Public Shared Function ColorDWB(ByVal Value As Decimal, ByVal MaxPositive As Decimal, 
ByVal Neutral As Decimal, ByVal ColStr As String) As String 
Dim ColVar1 As Integer Dim ColVar2 
As Integer Dim ColVar3 As Integer ‘Split the #RGB color to R, G, and B components 

ColVar1=Convert.ToInt32(left(right(ColStr, 6),2),16) 
ColVar2=Convert.ToInt32(left(right(ColStr, 4),2),16) 
ColVar3=Convert.ToInt32(right(ColStr, 2),16) ‘Find Largest Range Dim decPosRange 
As Decimal = Math.Abs(MaxPositive – Neutral) ‘Find appropriate color shade 
Dim Shd As Decimal = 255     

Dim iColor1 As Integer 
Dim iColor2 As Integer 
Dim iColor3 As Integer 
Dim strColor As String ‘Reduce a shade for each of the R,G,B components 
iColor1 = ColVar1 + CInt(Math.Round((MaxPositive-Value) * ((Shd – ColVar1) / decPosRange))) 
iColor2 = ColVar2 + CInt(Math.Round((MaxPositive-Value) * ((Shd – ColVar2) / decPosRange))) 
iColor3 = ColVar3 + CInt(Math.Round((MaxPositive-Value) * ((Shd – ColVar3) / decPosRange))) 

strColor = “#” & iColor1.ToString(“X2”)  & iColor2.ToString(“X2”) & iColor3.ToString(“X2”)     
Return strColor 
End Function 

它不是第一个给我同样错误的代码。我对VB不太了解。我在这里错过了什么?

【问题讨论】:

  • 你的代码没有返回任何东西,返回行被注释了
  • 谢谢。我想我纠正了它。但现在它显示“预期语句结束”

标签: sql vb.net reporting-services heatmap


【解决方案1】:

我已经更正并测试了您的功能:

Public Shared Function ColorDWB(ByVal Value As Decimal, ByVal MaxPositive As Decimal, ByVal Neutral As Decimal, ByVal ColStr As String) As String
        Dim ColVar1 As Integer
        Dim ColVar2 As Integer
        Dim ColVar3 As Integer
        'Split the #RGB color to R, G, and B components 
        ColVar1 = Convert.ToInt32(left(right(ColStr, 6), 2), 16)
        ColVar2 = Convert.ToInt32(left(right(ColStr, 4), 2), 16)
        ColVar3 = Convert.ToInt32(right(ColStr, 2), 16)
        'Find Largest Range 
        Dim decPosRange As Decimal = Math.Abs(MaxPositive - Neutral)
        'Find appropriate color shade 
        Dim Shd As Decimal = 255
        Dim iColor1 As Integer
        Dim iColor2 As Integer
        Dim iColor3 As Integer
        Dim strColor As String
        'Reduce a shade for each of the R,G,B components 
        iColor1 = ColVar1 + CInt(Math.Round((MaxPositive - Value) * ((Shd - ColVar1) / decPosRange)))
        iColor2 = ColVar2 + CInt(Math.Round((MaxPositive - Value) * ((Shd - ColVar2) / decPosRange)))
        iColor3 = ColVar3 + CInt(Math.Round((MaxPositive - Value) * ((Shd - ColVar3) / decPosRange)))
        'Return the new color 
        strColor = "#" & iColor1.ToString("X2") & iColor2.ToString("X2") & iColor3.ToString("X2")
        Return strColor
    End Function

也许你需要做一些修复,但它确实有效。

这是一个小提琴:https://dotnetfiddle.net/g3nR0O

【讨论】:

  • 完美运行!!非常感谢你,里卡多!!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-16
相关资源
最近更新 更多