01-15-2010 03:48 PM
Hello,
trying the new IIF command I'm a little surprised. Run the following code:
Dim a,b
a=1
b=3
logfilewrite(IIF(a>0, b/a, a/b))
a=0
b=3
logfilewrite(IIF(a>0, b/a, a/b))
And you'll get an division by 0 error in the second case. But that's exactly what I would like to prevent with this IIF statement. This example is not verry usefull but there are many cases where this behaviour leads to trouble. Like in the following "usefull" line of code:
logfilewrite(IIF(RootPropExist("MyProp"),RootPropValGet("MyProp"),"DefaultValue"))
Has anyone a workaround keeping this an inline statement?
Best Regards
Martin Liese
Solved! Go to Solution.
01-17-2010 09:26 AM
Hello Martin!
IIF is like any other VBS function calls. All paramters are evaluated before the function is called. In general it is OK in the case of IIF it is sometimes annoying. The solution is to build your own IIF equivalent function:Public Function IIFX( ByRef Compare, ByRef FalseExpr, ByRef TrueExpr ) If Compare <> 0 Then IIFX = Eval(TrueExpr) Else IIFX = Eval(FalseExpr) End If End Function
The drawback is the you have put the false and true expression in a string. Bad to read and sometimes a little difficult to write. Your example has to bechanged to:logfilewrite(IIFX(RootPropExist("MyProp"),"RootPropValGet(""MyProp"")","""DefaultValue"""))
Matthias
Matthias Alleweldt Project Engineer / Projektingenieur | Twigeater? |
10-29-2012 08:09 AM
For anyone finding this question from google, I had a similiar problem with this solution. http://www.adamjamesnaylor.com/2012/10/29/SQL-Server-Reporting-Services-IIf-Function-Evaluating-True...