Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Shared Variable Duplication Problem.. Post Reply Post New Topic
Author Message
BadBoyHouse
Newbie
Newbie


Joined: 25 May 2010
Online Status: Offline
Posts: 20
Quote BadBoyHouse Replybullet Topic: Shared Variable Duplication Problem..
     Posted: 04 May 2012 at 3:42am
I have report which uses a sub-report.
 
The sub-report works out a calculation which is then stored in a Shared Variable.  I use the shared variable in the main report to show as a group total figure - there are 6 rows - one for each change in the group.
 
The problem I'm having is that if the first row has a positive total for the shared variable, and the second row has a 0.00 total for the shared variable, the shared variable for the second row is a duplicate of the shared variable of the first row i.e. it shows the same total and no 0.00.
 
Can anyone suggest what might cause this?
 
Hope this makes sense!
 
 
IP IP Logged
Gurbs
Senior Member
Senior Member
Avatar

Joined: 16 Feb 2012
Location: Ireland
Online Status: Offline
Posts: 216
Quote Gurbs Replybullet Posted: 04 May 2012 at 4:18am
I'm not sure what is causing this, what I do know is that I had this exact problem a couple of days ago. What worked for me, was creating a second shared variable in your main report. The formula for that was something like

Shared numbervar NAME;
NAME := 0;

with NAME being the same name as your other shared variable.

You just got to make sure this is run before your subreport is running.

What it does is setting the shared variable 0 for all values. After that, when your subreport is running, it only overwrites those that are other than 0 in the subreport
IP IP Logged
BadBoyHouse
Newbie
Newbie


Joined: 25 May 2010
Online Status: Offline
Posts: 20
Quote BadBoyHouse Replybullet Posted: 04 May 2012 at 4:43am
Wow that worked Wink
 
It's amazing that someone else in the world had this exact same problem just a few days ago!
 
How did you figure out this as a solution?
IP IP Logged
Gurbs
Senior Member
Senior Member
Avatar

Joined: 16 Feb 2012
Location: Ireland
Online Status: Offline
Posts: 216
Quote Gurbs Replybullet Posted: 04 May 2012 at 4:47am
All credits for this one are for DBlank, he's the one that suggested it to me. i'm just spreading the love!
IP IP Logged
BadBoyHouse
Newbie
Newbie


Joined: 25 May 2010
Online Status: Offline
Posts: 20
Quote BadBoyHouse Replybullet Posted: 04 May 2012 at 4:59am
well cheers anyway. that's helped me out no end.
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 04 May 2012 at 6:04am
you should remember to reset your variables as needed.  Since a subreport may not run and overwrite the variable as you anticipate.
 
it also helps in the debugging, and kindof allows for a standard rule of 3 formulas for a shared variable (reset, increment, display) to be followed.
 
not that I haven't forgotten to reset variables, silly me
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum