Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Global Array Post Reply Post New Topic
Author Message
jpterry
Newbie
Newbie
Avatar

Joined: 09 Feb 2012
Location: United States
Online Status: Offline
Posts: 25
Quote jpterry Replybullet Topic: Global Array
     Posted: 17 Oct 2012 at 9:26am
I need to decalare a global array, but it doesn't seem to be able to maintain the inserted values. I assume that I'm not declaring it correctly. In the Formula Field where my calculation takes place, I say:
 
Global NumberVar Array x;
Redim x[24];
 
if PreviousIsNull({hrtables_Ent.n1}) then  // Check for the first record
  x[1] := {hrtables_Ent.n1}                     // Get the initial number (70,000)
else                                                       // On everythinig else
  x[GroupNumber] := x[GroupNumber - 1] * 1.04  // iterate through the
                                                            // Group # (1 - 24 in this case)
                                                            // and multiply the previous #
                                                            // by 4 percent
 
It appears to give me the first number, but then zeros for the remainder. Does the declaration of the variable have to take place somewhere else?  JPT


Edited by jpterry - 17 Oct 2012 at 11:08am
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 18 Oct 2012 at 4:48am
I don't see where you are iterating through the values or setting the GroupNumber...otherwise the code looks fine.
IP IP Logged
jpterry
Newbie
Newbie
Avatar

Joined: 09 Feb 2012
Location: United States
Online Status: Offline
Posts: 25
Quote jpterry Replybullet Posted: 18 Oct 2012 at 7:27am
GroupNumber (it could have easily been RecordNumber) increments through each iteration. I've been running tests to figure out what's happening and I see that each time the Formula is entered, the variable array, even through declared as Global, is reinitialized, so it does NOT maintain the data entered from the last iteration. That's why I wonder if I'm declaring the array in the proper place?  JPT
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 18 Oct 2012 at 10:36am
I would think that redim is reinitializing it.
 
you could put the 'creation' in say the report header and then just access the array in teh formula...that should take care of the reinitializing.
IP IP Logged
jpterry
Newbie
Newbie
Avatar

Joined: 09 Feb 2012
Location: United States
Online Status: Offline
Posts: 25
Quote jpterry Replybullet Posted: 19 Oct 2012 at 4:20am
I'm not familiar with putting variables in the Report Header. Is there a special "creation" command to allow for this?  JPT

Edited by jpterry - 19 Oct 2012 at 4:24am
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 19 Oct 2012 at 5:38am
no...that's why it's in quotes.
just create a formula like:
Global NumberVar Array x;
Redim x[24];
 
put it in the report header, since you only need to dim the array once per run of the report...if this is a false statement, put the formula in the group header that you need to reinitialize the array.
 
the only change to your existing formula would be to remove the line:
Redim x[24];
 
now your array should behave as desired.
 
HTH
IP IP Logged
jpterry
Newbie
Newbie
Avatar

Joined: 09 Feb 2012
Location: United States
Online Status: Offline
Posts: 25
Quote jpterry Replybullet Posted: 19 Oct 2012 at 8:13am
Thank you ... what I didn't know was that I had to re-declare the variable in the detail formula, as well, otherwise I kept getting an "unknown" error.  JPT+

Edited by jpterry - 19 Oct 2012 at 8:15am
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