Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Grouping by 10

Status
Not open for further replies.

sopomeres

MIS
Jan 16, 2003
61
US
I would like to list students names randomly in groups of 10. How could I do this?

The field is {students.student}

Thank you.
Chuck

 
Hi

heres the code

Is there a way to limit how many records appear in each group?

For example, how do you limit a group to have only 3 records appear in the Details section, regardless of the number of records there are in the group?


Solution

Use the following method:

1. Insert a section below on the Details section so that there is a Details A and Details B.

2. Create the following formulas:

@Formula1

WhilePrintingRecords;
NumberVar Number := 0;

@Formula2

WhilePrintingRecords;
NumberVar Number;
Number := Number + 1;

3. Place @Formula1 in the Group Header. Format the formula to Suppress.

4. Place @Formula2 in Details A. Format the SECTION (not the formula) to Suppress.

5. Format the Details B section to conditionally Suppress by selecting the X+2 button INSTEAD of the selecting the Suppress box. This launches the conditional formatting Formula Editor.

6. Enter this formula:

{@formula2} > 3

When you preview the report you will only see 3 records per group.


cheers

pgtek


--------------------------------------------------------------------------------
 
pgtek - I really don't see how this "randomly displays student's names in Groups of ten"...the moment you assign a group you have lost your randomness.

Chuck - This can be done in the report footer...you can store the values of the student's names in an array as you cycle through the records in the main part of the report....this can be suppressed if you have nothing to display there.

Now in the report footer section (A) which is suppressed you take the array that you have created and "shuffle" it to randomly distribute the array elements.

This can easily be done with a one pass shuffle that is often used to shuffle cards in card playing programs.

I will use a 5 element array to illustrate the principle....essentially the algorithm is to randomly select a number between 1 and 4...then swap the value in array element 5 with the random selection you have made. then you loop back and generate a random number between 1 and 3 and swap this with element 4...again a random number between 1 and 2 and swap this with element 3....

this effectively shuffles the "deck" with each array element moving about twice on average during the shuffle.

Now you would create display formulas to display the shuffled names in Report footer sections (B)...etc. The number of these display formulas will depend on the size of the student names (remember the 254 char limit/formula) and the number of student names involved....hopefully there are less than 1000 so that only one array is involved....but the same shuffle/display can be done with two or more arrays (though they are in separate arrays for purposes of the "shuffle" you treat them as though it was one large array).

If you like this approach give more details and we can try to code it.

Jim Broadbent
 
pgtek--you really should cite your sources.

sopomeres--

I think you could accomplish this my using the random function. Create a formula:

rnd()

Place this on your report and then use it as your sort field. (At least I think this is how you use the random function!)

I don't think there is a way of creating actual groups based on the number of group members without hard coding them, but you can mimic grouping by creating a formula:

if recordnumber in 1 to 10 then "Group 1" else
if recordnumber in 11 to 20 then "Group 2" else
if recordnumber in 21 to 30 then "Group 3" //etc.

Add this to the report and then to separate the groups, you could format the details section for a new page after
using this formula:

remainder(recordnumber,10)= 0

Or you could insert another details section_b and go to format section->details_b->suppress blank section->x+2 and enter:

remainder(recordnumber,10)<> 0

-LB
 
Nevermind the randomness. Would there be a way to prompt a user to enter the grouping size. For instance, the user will refresh and tell CR to make the group size 18. Any way to do this?

I'm learning here folks...thanks for your help!

-Chuck
 
I don't know what you mean by Grouping size...unless you are following lBass's approach....the problem there is that I see you getting the same names over and over again since the query that crystal generates will bring back the records in a certain order....

Jim Broadbent
 
Create a discrete number parameter {?NoInGrp}

Then change the formula to:

if recordnumber in 1 to {?NoInGrp} then &quot;Group 1&quot; else
if recordnumber in {?NoInGrp}+1 to {?NoInGrp}*2 then &quot;Group 2&quot; else
if recordnumber in {?NoInGrp}*2+1 to {?NoInGrp}*3 then &quot;Group 3&quot; else
if recordnumber in {?NoInGrp}*3+1 to {?NoInGrp}*4 then &quot;Group 4&quot; else &quot;Group 5&quot; //etc.

Then format the details_b section to &quot;suppress blank section&quot; based on the formula:

remainder(recordnumber, {?NoInGrp}) <> 0

Again these are not actual groups, but instead, clusters of records.

-LB
 
lbass is right on the money. Using his technique with a couple of minor tweaks, I was able to accomplish randomness and having the &quot;cluster&quot; number parameter driven.

Try these steps (all are based upon lbass's steps):

Create two detail sections, A and B. You can do this by right clicking the gray area on the right and choosing &quot;Insert Section Below&quot; from the pop up menu.

Create a formula called &quot;Random&quot; with this in it:

rnd(1)


Add the formula to your detail section B and suppress it.
Add your student field to detail section B as well.

Create another formula called &quot;GroupName&quot; and place this in it:

&quot;Group &quot; + ToText(Truncate(recordnumber/{?NoInGrp}))

Add the formula to your detail section A.

In the Field Explorer, create a new Parameter field called &quot;NoInGrp&quot; and make sure it is of type &quot;Number&quot;.

Right Click Details A and shoose Format Section.
Select the X+2 button next to Suppress and the following:

Remainder(recordnumber,{?NoInGrp}) <> 1

Lastly, add the @Random formula to Report->Sort Records.

Save the report and Test it.

Again as lbass pointed out, they are not true groups, but clusters of records that appear to be groups. Every time that you run the report, your students will be in a different order and potentially in different groups.

~Brian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top