| Author |
Message |
jensohl94
Newbie
Joined: 19 Jun 2015
Online Status: Offline
Posts: 5
|

Topic: Shared Variables in formulas Posted: 30 Oct 2015 at 8:34am |
|
I have placed a subreport in the Details "A" section. This subreport is passing a shared numbervar to the main report. (It calculates the # of days between 2 dates).
I placed the shared variable in Details "B" section and it displays correctly.
HOWEVER...
I want to use that value in a formula in Details "B" section. The minute I add the shared variable into a formula to add to another date in the main report, the shared variable gets set to 0...just on the first record. And then all of the other records are 1 off. What am I missing here?
|
IP Logged |
|
|
|
hilfy
Admin Group
Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
|

Posted: 02 Nov 2015 at 7:46am |
|
Initialize the variable to either 0 (for a number) or a blank string (for a string) in a section above Details A in the main report. Use it in the subreport.
What is the formula that you're trying to use it in for Details B?
-Dell
|
|
|
IP Logged |
|
jensohl94
Newbie
Joined: 19 Jun 2015
Online Status: Offline
Posts: 5
|

Posted: 02 Nov 2015 at 10:30am |
|
Subreport in Details Section A:
WhilePrintingRecords;
Shared numbervar payPeriodDiff := datediff("d",{CCalendar.periodBegin},{CCalendar.periodEnd});
payPeriodDiff
Formula I am trying to use this in, in Details Section "B":
WhilePrintingRecords;
datevar newHireAdd;
shared numbervar payPeriodDiff;
datevar newHireStartRT;
if {@YYYPayFrequency} = 'Weekly'
then
newHireAdd := cdate(dateadd("ww",1,{@NewHireRT}))-1
else if {@YYYPayFrequency} = 'Bi-Weekly'
then
newHireAdd := cdate(dateadd("ww",2,{@NewHireRT}))-1
else if {@YYYPayFrequency} = 'Monthly'
then
newHireAdd := cdate(dateadd("m",1,{@NewHireRT}))-1
else if {@YYYPayFrequency} = 'Semi-Monthly'
then
newHireAdd := cdate(dateadd("d",payPeriodDiff,newHireStartRT));
If I display the shared variable separately in a formula in Details B, it shows the correct number. However when it is used in the formula to add to the date in the same section, it is 0. The parameter it is using is the "Semi-Monthly" one.
Edited by jensohl94 - 02 Nov 2015 at 10:31am
|
IP Logged |
|
hilfy
Admin Group
Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
|

Posted: 03 Nov 2015 at 4:08am |
|
Are you using this to display newHireAdd? What happens if you keep all of this details b formula and then put "newHireAdd" (without the quotes) on the last line or take the semi-colon off the end of the formula?
-Dell
Edited by hilfy - 03 Nov 2015 at 4:09am
|
|
|
IP Logged |
|
jensohl94
Newbie
Joined: 19 Jun 2015
Online Status: Offline
Posts: 5
|

Posted: 03 Nov 2015 at 8:11am |
|
Yes, I am using that field to display newHireAdd. Adding the variable to the end of the formula did not make a difference.
|
IP Logged |
|
jensohl94
Newbie
Joined: 19 Jun 2015
Online Status: Offline
Posts: 5
|

Posted: 03 Nov 2015 at 8:13am |
|
It appears that on the first record the variable shows as 0, when added to the date. Then the next record it adds what the 1st record was supposed to be? For some reason the formula isn't recognizing the variable on the first record?
|
IP Logged |
|
hilfy
Admin Group
Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
|

Posted: 03 Nov 2015 at 8:15am |
|
Is the subreport above the section where you're using the date or below it? It must be above it.
-Dell
|
|
|
IP Logged |
|
jensohl94
Newbie
Joined: 19 Jun 2015
Online Status: Offline
Posts: 5
|

Posted: 03 Nov 2015 at 8:23am |
Okay. It seems to be working now. Why...I have NO idea. I decided to create a new formula with just the line of code that adds the variable to the date. It worked. So then I copied the code from the original formula, into the new one and it still works. So odd...
|
IP Logged |
|
|
|