Sunday, February 19, 2012

IIF Execution

I'm having a problem getting this iif statement to execute properly.
=IIF(Fields!AlarmLevel.Value = 0, "",
Code.rptUtilities.GetPeakLevel(Fields!ThresholdFormat.Value,
Fields!SpectrumFormat.Value, CType(Fields!Spectrum.Value, Byte()),
CType(Fields!Threshold.Value,Byte())) )
It seems as though it executes both the true and false parts and my textbox
always shows #Error when it should have evaluated to "".
The logic above is correct because I have done this
IIF(Fields!AlarmLevel.Value = 0, "1", "2") and it correctly displays on the
report.
GetPeakLevel will never work if the AlarmLevel is 0, so I figured I could
conditionally execute GetPeakLevel.
I know that is executing true and false part because I can place a try catch
in GetPeakLevel and return "" when it catches the error. This is not useful
though as any level other than 0 that catches an error would return "".
Does anyone know if this behavior is by design, or a bug.By design. That is how iif works. You could do code behind and use that
instead.
Bruce Loehle-Conger
MVP SQL Server Reporting Services
"Jeff" <Jeff@.discussions.microsoft.com> wrote in message
news:364451B0-F89C-417E-A925-DA77B2DB9181@.microsoft.com...
> I'm having a problem getting this iif statement to execute properly.
>
> =IIF(Fields!AlarmLevel.Value = 0, "",
> Code.rptUtilities.GetPeakLevel(Fields!ThresholdFormat.Value,
> Fields!SpectrumFormat.Value, CType(Fields!Spectrum.Value, Byte()),
> CType(Fields!Threshold.Value,Byte())) )
>
> It seems as though it executes both the true and false parts and my
textbox
> always shows #Error when it should have evaluated to "".
>
> The logic above is correct because I have done this
> IIF(Fields!AlarmLevel.Value = 0, "1", "2") and it correctly displays on
the
> report.
>
> GetPeakLevel will never work if the AlarmLevel is 0, so I figured I could
> conditionally execute GetPeakLevel.
>
> I know that is executing true and false part because I can place a try
catch
> in GetPeakLevel and return "" when it catches the error. This is not
useful
> though as any level other than 0 that catches an error would return "".
>
> Does anyone know if this behavior is by design, or a bug.
>

No comments:

Post a Comment