x
• Status: Solved
• Priority: Medium
• Security: Public
• Views: 646

Crystal Reports Multi-line Replace Fails - only last line executed

I have a formula that creates a long string with fractions in sixteenths. I want to replace, for example, 2/16 with 1/8 and 4/16 with 1/4, etc.

My original Formula is @ReportSize
My new formula which I use to display the size string is @ReportSizeFrac which is shown below. It seems that only the last line is working. None of the others are working. I still see 5-8/16 instead of 5-1/2.

Local StringVar HoldString;
HoldString :=replace({@ReportSize},"-0/16","");
HoldString :=replace(HoldString,"-2/16","-1/8");
HoldString :=replace(HoldString,"-4/16","-1/4");
HoldString :=replace(HoldString,"-6/16","-3/8");
HoldString :=replace(HoldString,"-8/16","-1/2");
HoldString :=replace(HoldString,"-10/16","-5/8");
HoldString :=replace(HoldString,"-12/16","-3/4");
HoldString :=replace(HoldString,"-14/16","-7/8");
HoldString :=replace(HoldString,"x0-","x");
HoldString :=replace(HoldString,".00","");
0
• 7
• 4
• 2
• +1
1 Solution

Commented:
All works here OK.

Can you show us a sample value for {@reportsize}
0

Commented:
Where do you see the value?

Did you put the formula with the replaces on the report?

Is that the entire formula?

mlmcc
0

Author Commented:
Here is what is currently getting printed:

Angle L1:2-0/16 L2:2-0/16x0-4/16x8-4/16

What it should print is:

Angle L1: 2 L2: 2 x1/4x8-1/4

The -0/16 should be replaced by null string
The -4/16 should be replaced by -1/4

If you look at the attached .PDF, the column labeled "Size" contains the values of @ReportSizeFrac
sample.pdf
0

Author Commented:
If it helps, here is the formula for @PageSize:

select {Fab_Item.SteelType}
case  "Plate": "Plate:"&{Fab_Item.sz_lth_in}&"-"&{Fab_Item.sz_lth_16}&"/16x"&{Fab_Item.sz_width_in}&"-"&{Fab_Item.sz_width_16}&"/16x"&{Fab_Item.sz_thickness_in}&"-"&{Fab_Item.sz_thickness_16}&"/16"
case  "Pipe": "Pipe: "&{Fab_Item.sz_width_in}&"x"&{Fab_Item.sz_thickness_in}&"x"&{Fab_Item.sz_lth_in}&"-"&{Fab_Item.sz_lth_16}&"/16"
case  "Beam": "Beam: "&{Fab_Item.size_in}&"x"&{Fab_Item.sz_width_in}&"x"&{Fab_Item.sz_thickness_in}&"x"&{Fab_Item.sz_lth_in}&"-"&{Fab_Item.sz_lth_16}&"/16"
case  "Channel": "Channel: "&{Fab_Item.size_in}&"x"&{Fab_Item.sz_width_in}&"x"&{Fab_Item.sz_thickness_in}&"x"&{Fab_Item.sz_lth_in}&"-"&{Fab_Item.sz_lth_16}&"/16"
case "Rect": "Rect. Tube: "&{Fab_Item.size_in}&"x"&{Fab_Item.sz_width_in}&"x"&{Fab_Item.sz_thickness_in}&"x"&{Fab_Item.sz_lth_in}&"-"&{Fab_Item.sz_lth_16}&"/16"
case "Rod": "Rod: "&{Fab_Item.sz_width_in}&"-"&{Fab_Item.sz_width_16}&"/16x"&{Fab_Item.sz_lth_in}&"-"&{Fab_Item.sz_lth_16}&"/16"
case "Round": "Round Tubing: "&{Fab_Item.sz_thickness_in}&"-"&{Fab_Item.sz_thickness_16}&"/16x"&{Fab_Item.sz_width_in}&"-"&{Fab_Item.sz_width_16}&"/16x"&{Fab_Item.sz_lth_in}&"-"&{Fab_Item.sz_lth_16}&"/16"
case "Angle": "Angle L1:"&{Fab_Item.size_in}&"-"&{Fab_Item.size_16}&"/16 L2:"&{Fab_Item.sz_width_in}&"-"&{Fab_Item.sz_width_16}&"/16x"&{Fab_Item.sz_thickness_in}&"-"&{Fab_Item.sz_thickness_16}&"/16x"&{Fab_Item.sz_lth_in}&"-"&{Fab_Item.sz_lth_16}&"/16"
default: ""
0

Commented:
Add a new first line to your formula field...

EvaluateAfter ({@ReportSize});

Try it again.
0

Author Commented:
Same result. No change. For example:
Round Tubing: 2-3/16x0-10/16x12-12/16
0

Author Commented:
To prove to myself that only the final Replace works, I copied the line:
HoldString :=replace(HoldString,"-12/16","-3/4");

to the bottom. Now I get:
Round Tubing: 2-3/16x0-10/16x12-3/4

Only the replacement of 12/16 by 3/4 is working now.
0

Commented:
All I can say then is that when I put these original values as variables in your formula I get correct results.

I have used this for testing various values and get correct results every time.

Local StringVar HoldString;
//Holdstring:="12-0/16, 4-2/16,7-3/16,123-6/16,245-7/16,23-8/16,32-9/16,42-10/16";
//Holdstring:= "Plate:19-0/16x3-8/16x0-4/16";
Holdstring:="Angle L1:2-0/16 L2:2-0/16x0-4/16x8-4/16";

HoldString :=replace(holdstring,"-0/16","");
HoldString :=replace(HoldString,"-2/16","-1/8");
HoldString :=replace(HoldString,"-4/16","-1/4");
HoldString :=replace(HoldString,"-6/16","-3/8");
HoldString :=replace(HoldString,"-8/16","-1/2");
HoldString :=replace(HoldString,"-10/16","-5/8");
HoldString :=replace(HoldString,"-12/16","-3/4");
HoldString :=replace(HoldString,"-14/16","-7/8");
HoldString :=replace(HoldString,"x0-","x");
HoldString :=replace(HoldString,".00","");
Holdstring
0

Author Commented:
Interesting, I copied the line:
HoldString :=replace(HoldString,"-10/16","-5/8");

to the bottom and now I get:
Round Tubing: 2-3/16x0-5/8x12-3/4

Now the last 2 replaces are working.

I kept going until I copied everything. Now everything is working! Here is what I ended up with. Can someone explain what is going on????

EvaluateAfter ({@ReportSize});
Local StringVar HoldString;
HoldString :=replace({@ReportSize},"-0/16","");
HoldString :=replace(HoldString,"-2/16","-1/8");
HoldString :=replace(HoldString,"-4/16","-1/4");
HoldString :=replace(HoldString,"-6/16","-3/8");
HoldString :=replace(HoldString,"-8/16","-1/2");
HoldString :=replace(HoldString,"-10/16","-5/8");
HoldString :=replace(HoldString,"-12/16","-3/4");
HoldString :=replace(HoldString,"-14/16","-7/8");
HoldString :=replace(HoldString,"x0-","x");
HoldString :=replace(HoldString,".00","");
HoldString :=replace(HoldString,"-12/16","-3/4");
HoldString :=replace(HoldString,"-10/16","-5/8");
HoldString :=replace(HoldString,"-14/16","-7/8");
HoldString :=replace(HoldString,"-8/16","-1/2");
HoldString :=replace(HoldString,"-6/16","-3/8");
HoldString :=replace(HoldString,"-4/16","-1/4");
HoldString :=replace(HoldString,"-2/16","-1/8");
HoldString :=replace(HoldString,"-0/16","");
HoldString :=replace(HoldString,"x0-","x");
0

Commented:
I can't explain that.

It looks like some sort of corruption in the formula field.  But you should now be able to delete the original lines and be good to go.
0

Author Commented:
This is what I get now. (see sample).

It looks like everything is working -- but I really don't know what I did to fix it.
sample2.pdf
0

Commented:
I wonder if some of the - were not really - but one of the other characters that look like it.  I recall that issue from a question here.

mlmcc
0

Commented:
mlmcc has a point.  That has come up here before where someone had used the wrong character.  But if I copy&paste the formula from your first post into CR, it works fine (I replace {@ReportSize} with the example string you posted later).  So, if you did a copy&paste from CR into your first post, then the characters in CR were probably fine.  I guess maybe if you pasted the formula into something else first and then copied it from there to here, that something else might have "translated" some characters into the "normal" ones.

James
0

Author Commented:
Apparently what I was doing was correct. No real explanation why it failed.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Featured Post

• 7
• 4
• 2
• +1
Tackle projects and never again get stuck behind a technical roadblock.