Search code examples
crystal-reportsreport

How to add Line Break dynamically in crystal report formula


I have a formula field in my crystal report which is set as "Html Text" in text interpretation. I want to add Line Break So I simply use this

"<br>"&{MyField}

But I want to add Line break dynamically such as it should be aligned according to my field value. For example, if field value is 2 then there will be 2 line breaks or if value is 5 then line breaks will be 5 like this.....

if {LineBreak} = 5 then
"<br><br><br><br><br>"&{MyField}

if {LineBreak} =2 then
"<br><br>"&{MyField}

How can I achieve this?


Solution

  • Use a loop to add <br>s; something like:

    Local NumberVar i;
    Local StringVar lineBreaks;
    
    lineBreaks := "";
    for i := 1 to {LineBreak} do (
        lineBreaks := "<br>" & lineBreaks;
        );
    
    lineBreaks & {MyField};