Search code examples
textcrystal-reportsword-wrap

Crystal Reports- How can I format a text object that wraps to automatically insert text at the beginning of each line?


Here is an example:

CSA.1169-1342, 1169-1342, 1349-1353, 
1349-1353, 1355-1368, 1355-1368, 
1371-2498, 1371-2498, 2501-2661, 
2501-2661, 2665-2691, 2665-2691, 
2693-2893, 2693-2893, 2897-3000, 
2897-3000

I need each line to start with the Prefix CSA. Which comes from a different field. I also created this string from two separate fields which independently render 1349 and 1342 and add the - and the commas. The Goal is to be able to keep the object the same width while the text sizes may actually change and allow the field to wrap and include a prefix each time it wraps. Here is another example of the field :

CRTX.220-239, 220-239, 241-249, 
241-249, 251-948, 251-948, 
90-218, 90-218, 950-983, 
950-983, 985-1000, 985-1000, 

What I need is for the result to render the following regardless to when the object wraps:

CRTX.220-239, 220-239, 241-249, 
CRTX.241-249, 251-948, 251-948, 
CRTX.90-218, 90-218, 950-983, 
CRTX.950-983, 985-1000, 985-1000,

My intent is to have this inserted as a sub report that is linked to a group. The CRTX in the string would be what links the sub-report.


Solution

  • Im not aware of the ability to do this dynamically as you size the field but with the following formula the statement containing mod can be changed, this will provide the output in your question. change to mod 4 = 0 will output four numbers per line etc.... (change the field to can grow)

    numbervar a;
    stringvar prefix := split({yourfeild},".")[1];
    stringvar data := split({yourfeild},".")[2];
    stringvar array numbers := split(data,",");
    numbervar counter := ubound(split(data,","));
    stringvar output;
    for a := 1 to counter do 
    (
    if a mod 3 =0 then output := output + trim(numbers[a]) +", " + chr(13) +  prefix +"."
    else output := output + trim(numbers[a]) +", "
    );
    output := prefix + "."+mid(output,1,len(output)-2)