Oleg Oleg - 3 months ago 27
SQL Question

Error after I inserted custom code in SSRS

enter image description here

After I inserted custom code in my SSRS report I got this error:

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.


All I am trying to do is create a Excel like heat map based on shades of colors.
My custom code:

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


And its not a first code that gives me the same error. I dont know much about VB. What am I missing here?

Answer

I've corrected and tested your function:

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

Maybe you need to do some fixes, but it works.

Here is a fiddle: https://dotnetfiddle.net/g3nR0O

Comments