Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Random Number at Group level Post Reply Post New Topic
Author Message
Edchad5533
Newbie
Newbie
Avatar

Joined: 21 Jan 2008
Location: United States
Online Status: Offline
Posts: 7
Quote Edchad5533 Replybullet Topic: Random Number at Group level
     Posted: 21 Jan 2008 at 2:39pm
I am creating report where I need to random select records to be auditted at a group level. I am generating the random number and creating a integer from it for selection purposes with out problem. When I try to use the integer to select which records to select within the group to be auditted, the random number is being re-generated and a new integer value is being created. Group level calcs done thru formulas.
 
For example, at group level;
 
Random Number  generated is 0.72  The integer created is 7.
 
at Detail level;
 
the 7th record of detail is not marked.
 
I found that the integer value (formula) created at group level changes because the formula that creates it is tied to the random number formula which changes value each time indirectly accessed. 
 
Does anyone have any suggestions as to how I could lock the group level formulas so I can use them in the record selection process?
 
Thanks in advance
 
edchad5533   
IP IP Logged
Lugh
Senior Member
Senior Member
Avatar

Joined: 14 Nov 2007
Online Status: Offline
Posts: 377
Quote Lugh Replybullet Posted: 22 Jan 2008 at 6:24am
Well, the simplest method is to store the random number in a Global variable, which is not set in the same formula in which it is read.  E.g., set up two formulas, @SetRandom and @ReadRandom, that look like so:

@SetRandom
Global NumberVar MyRnd;

MyRnd := Rnd();
MyRnd := Floor( MyRnd * 10 );


@ReadRandom
Global NumberVar MyRnd;

If RecordNumber = MyRnd Then
True
Else
False;


Put @SetRandom in your group header.  @ReadRandom probably actually ought to be in a suppress condition of the details section, rather than a separate named formula, but regardless it should be in your details section.

This should reset your random number with each new group header, but it won't get reset within a group.


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