problem with complex expression

2 posts, 0 answers
  1. kellyroberts
    kellyroberts avatar
    45 posts
    Member since:
    Jul 2007

    Posted 04 May 2010 Link to this post

    Hi All -

    oiy! this one is a pain.  I have a column in a dataset that is technically string but in reality has both string and numeric values.  well I want to test for numeric values ... and then format accordingly. so for example suppose i have a dataset that goes ...

    10
    20
    30
    apple
    40
    50

    I want the format to be currency. here is my expression.  *IsNumeric is a UDF that simply wraps Microsoft.VisualBasic.IsNumeric.*

    =iif(IsNumeric(Fields.[YTD Target]),Format("{0:c}",CDbl(Fields.[YTD Target])),Fields.[YTD Target])

    well the report bombs on 'apple' citing 'Input was not in correct format.

    The only thing I can figure is that both True and False parts are fully evaluated when IIF is called.. so in the case of 'apple' the True part will surely fail eventhough isNumeric("apple") = False
  2. Peter
    Admin
    Peter avatar
    1611 posts

    Posted 06 May 2010 Link to this post

    Hello kellyroberts,

    The experienced behavior is correct and by design. As you can see IIF() is a Function and you need to prepare the parameters prior to executing the function. 

    That's why the reporting engine first evaluates the function parameters and then pass the values to the function. 

    Our suggestion would be to use an User Function instead of IIF as shown in the code snippet:
    Public Shared Function CustomFormat(ByVal value As String) As String
        If IsNumeric(value) Then
            Return FormatCurrency(Convert.ToDouble(value))
        Else
            Return value
        End If
    End Function

    Give it a try and let us know how it goes.

    All the best,
    Peter
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. DevCraft banner
Back to Top