在 SSRS 中插入自定义代码后出错
Error after I inserted custom code in SSRS
在我的 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 了解不多。我在这里错过了什么?
我已经更正并测试了你的功能:
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
也许您需要做一些修复,但它有效。
这是一个fiddle:https://dotnetfiddle.net/g3nR0O
在我的 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 了解不多。我在这里错过了什么?
我已经更正并测试了你的功能:
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
也许您需要做一些修复,但它有效。
这是一个fiddle:https://dotnetfiddle.net/g3nR0O