Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Problem with global datevar Post Reply Post New Topic
Author Message
Hartley
Newbie
Newbie


Joined: 22 Mar 2012
Online Status: Offline
Posts: 2
Quote Hartley Replybullet Topic: Problem with global datevar
     Posted: 22 Mar 2012 at 3:41am
Apologies in advance if this is in the wrong place.

I've been wrestling with a report (Crystal 11) for over a day now and I'm at my wit's end.

The report is essentially a customer account statement, showing invoices (type I) and payments (type P) in the detail section and outputting a balance in the page footer.

What I also need to do in the page footer is use a formatting formula to display a red 'overdue' stamp if the earliest invoice item was before a certain date.

So, what I've done is:
1. In the report header, add the global declaration:
Global DateVar FirstInvoice;

2. In the detail section, add this formula to catch the date of the earliest invoice item:
Local DateVar Dummy; // test for an unitialised variable
Global DateVar FirstInvoice;
IF {TransactionsTable.transactionType} = "I" Then
   IF FirstInvoice = Dummy Then
      FirstInvoice := {TransactionsTable.transactionDate}
   ELSE IF DateDiff("d",{TransactionsTable.transactionDate},FirstInvoice) > 0 Then
      FirstInvoice := {TransactionsTable.transactionDate};

3. In the page footer, attempt to output the value of the global (I was trying to work with it initially, but fell back to just outputting it because it wasn't working - it still isn't )
Global DateVar FirstInvoice;
FirstInvoice;

The formula in the details section outputs the correct value i.e. that of the earliest invoice item, but when we get to the page footer, nothing's output at all - the variable is empty.

I'm pretty sure this is down to my unfamiliarity with Crystal, but I can't seem to find an answer to the problem. Could anyone point me in the right direction, please?

Best,

Hart

Edited by Hartley - 22 Mar 2012 at 3:45am
IP IP Logged
Hartley
Newbie
Newbie


Joined: 22 Mar 2012
Online Status: Offline
Posts: 2
Quote Hartley Replybullet Posted: 22 Mar 2012 at 3:51am
Blow me if I haven't just sorted it, five minutes after posting that.

Change the declaration to Shared, and all is well.

Now, Crystal, that's more than a bit naughty - Globals are not global? Can anyone explain what's going on with the scope, there?

Best,

Hart
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 22 Mar 2012 at 8:12am
it is defined in help but....
local - scope only exists in the formula
global - scope is the entire report (but a subreport is another report)
shared - scope is across all reports.
 
local makes sense. global was probably developed at the same time, and makes sense for the report....
shared probably came later as they found that the need to pass variables from subreports.  Since global was already in the logic of the report, and from experience changing a variables meaning in a large project is a pain and prone to mistakes, they probably left it and just added the 'shared' option.
 
Again, global is global...just to the report, and a subreport is a separate entity (that's the part we all miss, but in other reporting systems it is infinitely recursable, hence each is it's own report).
 
I know, clear as mud.  Again it is well documented in the CR help, as that is where I found it.  Since I am lazy, I use only shared or local, and never worry about global.
 
HTH
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