This is a migrated thread and some comments may be shown as answers.

Text Insert method inside an IIf statement

2 Answers 108 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Amanda
Top achievements
Rank 1
Iron
Amanda asked on 05 Oct 2016, 09:57 PM

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 Answers, 1 is accepted

Sort by
0
Accepted
Katia
Telerik team
answered on 07 Oct 2016, 06:36 AM
Hello Amanda,

The reporting engine will first evaluate the function parameters and then will  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
0
Amanda
Top achievements
Rank 1
Iron
answered on 07 Oct 2016, 02:04 PM

Katia, thank you for your answer!

Tags
General Discussions
Asked by
Amanda
Top achievements
Rank 1
Iron
Answers by
Katia
Telerik team
Amanda
Top achievements
Rank 1
Iron
Share this question
or