Text Insert method inside an IIf statement

3 posts, 1 answers
  1. Amanda
    Amanda avatar
    30 posts
    Member since:
    Aug 2012

    Posted 05 Oct Link to this post

    Hello all!

    I've got a class tied to a report that I'm building, and 3 of the properties are City, State, and Zip.  Zip is not currently sent over with a dash, just the 5-9 numbers.

    I want to format zips on my report longer than 5 characters as "99999-9999", and Zips that are 5 characters "99999".  Fairly basic stuff.  I am also combining the City, State, and Zip of my report into 1 text box.

    I'm trying to get cute (which is always dangerous), but I'm hoping someone can explain why this code throws a 'Specified argument was out of the range of valid values. Parameter name: startIndex' when I go to preview the report.  If I don't have more than 5 characters, I don't want it doing the insert.  Since the 'test data' is empty (as I'm just previewing the design), it shouldn't be evaluating the Insert I wouldn't think.

    =Format("{0}, {1} {2}",Trim(Fields.City), Fields.State, IIf(Len(Fields.Zip)>5, Insert(Fields.Zip,5,"-"),Fields.Zip))

    Thanks for any info!

  2. Answer
    Katia
    Admin
    Katia avatar
    303 posts

    Posted 07 Oct Link to this post

    Hello Amanda,

    The reporting engine will first evaluate the function parameters and then will passe the result values to the function. It means that you need to make sure the parameters of the function are valid statements prior to executing the function.

    In your scenario, you can use ?: conditional operator, it will return one of two values depending on the value of a Boolean expression, for example:
    = Len(Fields.Zip)>5 ? Insert(Fields.Zip,5,"-") : Fields.Zip


    I hope this approach will help.


    Regards,
    Katia
    Telerik by Progress
    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 Feedback Portal and vote to affect the priority of the items
  3. DevCraft banner
  4. Amanda
    Amanda avatar
    30 posts
    Member since:
    Aug 2012

    Posted 07 Oct in reply to Katia Link to this post

    Katia, thank you for your answer!

Back to Top