Welcome, Guest
  • Page:
  • 1
  • 2

TOPIC: subreports inside a text box?

subreports inside a text box? 09 Jan 2007 04:34 #14093

  • DrewAllen
  • OFFLINE
  • Platinum Boarder
  • Posts: 1379
  • Karma: 1
DavidZ;8734 wrote:
Could I not have two shared variables that are set the value of the subreports and then a third formula that puts the other two together in a good format?

If this is possible are you able to elaborate on the details of the shared variables (how I define them and where, and where to place the subreports etc)


You can actually do this with only one shared variable. You will need three formulas, though. You will need at least three sections: sub-report 1 goes in the first section; sub-report 2 goes in the second section; and the final formula goes in the third section. Sections are evaluated from top to bottom (with appropriate loops for various groups). Putting the sub-reports and the final formula in separate sections forces the correct order of evaluation.

4I don't know what method Crystal uses to determine the order of evaluation within a section. When the formulas are at the same level, you can use the EvaluateAfter to force a particular order, but you can't do this when one formula is in a sub-report and the other is either in the main report or in a second sub-report. Because you can't force a particular order within a section, you need to put them in separate sections.

The actual code is very simple. As with many programming languages, you can declare a variable and assign a value in the same statement. For sub-report one, you simply assign the appropriate value to the shared variable. Make sure that the value has enough spaces at the end to separate the first result from the second. When sub-report 1 is blank, you want to return a zero length string ("").

Shared StringVar DavidsVar := <non-null string value for sub-report 1>;


In the second sub-report, you concatenate the existing value from sub-report 1 to that in sub-report 2.

Shared StringVar DavidsVar := DavidsVar + <non-null value for sub-report2>;


Finally, in the main report you display the value. You can't have a formula that only declares a variable, but you also don't want to change the variable. A semi-colon is required to separate statements within a formula.

Shared StringVar DavidsVar;
DavidsVar


If you want to have a particular separator such as "; " when both values exist, but none when either one is blank, then you can use an array variable. In this case, it is okay to return a null value, because you can account for that in the last formula.

Shared StringVar Array DV;
DV[1] := <SR1 value>;


Shared StringVar Array DV;
DV[2] := <SR2 value>;


Shared StringVar Array DV;
f1(DV[1]) + f2(DV[1],DV[2]) + f3(DV[2]);


Where f1() and f3() are functions that handle displaying that value including what do when it is Null and f2() is a function that determines what and when to display as a separator.

Drew
J. Drew Allen

Crystal Reports and SQL Server Consultant




It is better to live your destiny imperfectly than to live an imitation of somebody else's life with perfection.

subreports inside a text box? 09 Jan 2007 11:26 #14098

  • DrewAllen
  • OFFLINE
  • Platinum Boarder
  • Posts: 1379
  • Karma: 1
Many of the techniques described here are also used to suppress blank sub-reports. I've described the process in more detail in my blog and also uploaded a sample file that uses the techniques discussed there.

Drew
J. Drew Allen

Crystal Reports and SQL Server Consultant




It is better to live your destiny imperfectly than to live an imitation of somebody else's life with perfection.

subreports inside a text box? 16 Jan 2007 01:13 #14157

  • DavidZ
  • OFFLINE
  • Platinum Boarder
  • Posts: 703
  • Karma: 4
Thanks Drew,

I have now done this but I would like to supress the two sections above the main report so that they do not show the fields. When I suppress them the values do not show though. Is there any way around this?

Thanks

David

DrewAllen;8746 wrote:
You can actually do this with only one shared variable. You will need three formulas, though. You will need at least three sections: sub-report 1 goes in the first section; sub-report 2 goes in the second section; and the final formula goes in the third section. Sections are evaluated from top to bottom (with appropriate loops for various groups). Putting the sub-reports and the final formula in separate sections forces the correct order of evaluation.
The actual code is very simple. As with many programming languages, you can declare a variable and assign a value in the same statement. For sub-report one, you simply assign the appropriate value to the shared variable. Make sure that the value has enough spaces at the end to separate the first result from the second. When sub-report 1 is blank, you want to return a zero length string ("").

Shared StringVar DavidsVar := <non-null string value for sub-report 1>;


In the second sub-report, you concatenate the existing value from sub-report 1 to that in sub-report 2.

Shared StringVar DavidsVar := DavidsVar + <non-null value for sub-report2>;


Finally, in the main report you display the value. You can't have a formula that only declares a variable, but you also don't want to change the variable. A semi-colon is required to separate statements within a formula.

Shared StringVar DavidsVar;
DavidsVar


Drew
David Zeidman
Zeidman Development
www.zeidman.info

Check out our blog - www.re-decoded.com

subreports inside a text box? 16 Jan 2007 01:18 #14158

  • DavidZ
  • OFFLINE
  • Platinum Boarder
  • Posts: 703
  • Karma: 4
So I answered this myself.

If you suppress the row in the main report where the subreport sits no data will go through to the shared variable in the lower section.

However if you suppress the row inside the subreport the values still go through to the main report.

David
David Zeidman
Zeidman Development
www.zeidman.info

Check out our blog - www.re-decoded.com
  • Page:
  • 1
  • 2
Time to create page: 0.96 seconds