Go Premium for a chance to win a PS4. Enter to Win

x
Solved

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

Posted on 2013-02-04
Medium Priority
642 Views
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

LVL 77

Expert Comment

ID: 38853052
All works here OK.

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

LVL 101

Expert Comment

ID: 38853473
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 Comment

ID: 38853768
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 Comment

ID: 38853787
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

LVL 77

Expert Comment

ID: 38854063
Add a new first line to your formula field...

EvaluateAfter ({@ReportSize});

Try it again.
0

Author Comment

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

Author Comment

ID: 38855491
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

LVL 77

Expert Comment

ID: 38855558
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 Comment

ID: 38855589
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

LVL 77

Accepted Solution

peter57r earned 1000 total points
ID: 38855640
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 Comment

ID: 38855712
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

LVL 101

Expert Comment

ID: 38858010
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

LVL 35

Expert Comment

ID: 38858858
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 Closing Comment

ID: 38871701
Apparently what I was doing was correct. No real explanation why it failed.
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customerâ€™s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. â€¦
I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirementsâ€¦
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper cornâ€¦
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can eâ€¦
###### Suggested Courses
Course of the Month7 days, 12 hours left to enroll

#### 824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.