Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Shared Variables

Status
Not open for further replies.

sgk17

Technical User
Nov 8, 2002
68
US
I'm having a problem getting shared variables to work in Crystal 9.0. Can a shared variable be declared in a subreport and passed to the main report? Also, how do I match it record for record. For example, I want each record in the subreport to pass a value to each record in the main report. What I get though is the last value from the subreport being passed to every record in the main report. Neither of my reports have groups, but I've tried inserting groups. I'm putting the subreport before the main report. So far, nothing I've tried works. Also, can the value of my shared variable be conditional? Ex.
Shared numberVar myVar;
if(count < 10) then
Shared numberVar := 10
else if(count < 20) then
Shared numberVar := 20

Is this correct?
 
The solution lies in where you're placing the subreport.

If you need a distinct value for each row in the main report, then the subreport will have to fire for each row, and PRIOR to the detail band where it's used, which means poorer performance.

Right click the details section and select insert section below, then move your fields in there.

Now place the subreport into the first details section.

Make sure that you reset the shared variable PRIOR to the subreport firing (Group header before?):

Shared numberVar myVar :=0;

in case you don't get anything in the sub because otherwise it will retain it's last known value.

As for making a variable conditional, you can, but try it this way:

Shared numberVar myVar;
if(count < 10) then
MyVar := 10
else if(count < 20) then
MyVar := 20

-k
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top