Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replace formula bug or I am using it wrong.

Status
Not open for further replies.

dzavad

Programmer
Apr 17, 2000
167
US
I have formula in my CR 9 report that should display chosen parameter values on the report. All the values in it hardcoded.
Formula:
StringVar joinedParameterValuesRegion;
joinedParameterValuesRegion := Join({?Region}, " ; ");
(
joinedParameterValuesRegion,instr

(joinedParameterValuesRegion,"1281"),4);
joinedParameterValuesRegion := Replace (joinedParameterValuesRegion, "1" , "Vancouver – Coastal" );
joinedParameterValuesRegion := Replace (joinedParameterValuesRegion, "2" , "Interior" );
joinedParameterValuesRegion := Replace (joinedParameterValuesRegion, "5" , "North" );
joinedParameterValuesRegion := Replace (joinedParameterValuesRegion, "7" , "Fraser" );
joinedParameterValuesRegion := Replace (joinedParameterValuesRegion, "9" , "Vancouver Island");
joinedParameterValuesRegion := Replace (joinedParameterValuesRegion, "1281" , "Aboriginal Agency" );

Its prety simple logic. I am replacing one value with another. Evrything worked fine until I added one more value to it where I am replacing string "1281". For some reason Replace formula reads "1281" like 1,2,8,1. So for example ,if I in my Report Region parameter I select Region "1281"...Display on the report will show "Vancouver – CoastalInterior8Vancouver – Coastal". And it should show just "Aboriginal Agency".
Is this knowing isue or I am codding it wrong?
 
Hi,
Not sure how to correct it, but it is acting like it should..ANY 1, regardless of whether it is part of a larger string, will be replaced..same for all the others.


[profile]
 
The problem is in your structure. The first thing you're replacing is the number 1. "1281" instantly becomes "Vancouver – Coastal28Vancouver – Coastal". The next line, it becomes "Vancouver – CoastalInterior8Vancouver – Coastal". So by the time you get to the last line, the string no longer contains "1281", hence your problem.

If you move the "1281" replace statement before all of the others, that should work.

-dave
 
Hi,
I have another solution for you to try..instead using the
Replace function use use a CASE or IF statement(s) to test the incoming values and take the appropriate action..You could even leave them in the array and loop through it for the test, maybe...

[profile]
 
Thanks moving the "1281" replace statement before all of the others worked fine. Thanks a lot..I was giving up on it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top