Tip Of The Day - Printing Summary Using Sort Break and Arrays

Lerebours, Jose Jose.Lerebours at EagleGL.com
Thu Feb 23 12:24:54 PST 2006


How often do you print a detailed report where you
will need to provide a summary within your subtotal?

While tricky, they are not that difficult.  This is
one method I've used and proven to work just fine.
I am sure there are many other ways to skin this cat,
but here goes the one I've found to be very reliable.

In this example, we are going to pretend that we are
printing a daily sales report.  At the end of each day,
we want to know how much each sales person sold.  This 
information can be shown using any number of columns
(2 columns per sales person).  The summary should look
like so:

NOTE:  Following names are totally fictitious and do not
       refer to any real person or company.  8-)

  Jose          $2,500.00
  John          $3,200.00  
  Mark          $4,500.00  
  Brian         $3,800.00

Of course, you can add any additional information you
want such as Billed, Paid, Commission, etc. but I leave
this totally up to you.

OK, lets play:

  1  -------   -   -   -   -   -   -   -   -   -   -   -   
       ! If:                                               
       Then: '/** Here are the arrays you will need        
  2  -------   -   -   -   -   -   -   -   -   -   -   -   
       ! If:                                               
       Then: dim prtTXT(26):aa; dim sumTXT(1200)(220,*,g)  
  3  -------   -   -   -   -   -   -   -   -   -   -   -   
       ! If:                                               
       Then: dim sumKEY(1200)(10,*,g); la(4,.0); lb(4,.0)  
  4  -------   -   -   -   -   -   -   -   -   -   -   -   
       ! If:                                               
       Then: '/************************                    
  5  -------   -   -   -   -   -   -   -   -   -   -   -   
       ! If:                                               
       Then: '/**  your code here                          
  6  -------   -   -   -   -   -   -   -   -   -   -   -   
       ! If:                 'Lets find the summarized     
       Then: gosub DOSUMM    'spot for this record         
  7  -------   -   -   -   -   -   -   -   -   -   -   -   
       ! If:                                               
       Then: '/**  more of your code goes here             
  8  -------   -   -   -   -   -   -   -   -   -   -   -   
       ! If:                                               
       Then: print                                         
  9  -------   -   -   -   -   -   -   -   -   -   -   -   
       ! If:                                               
       Then: end                                           
 10  -------   -   -   -   -   -   -   -   -   -   -   -   
DOSUMM ! If:                 'Lets say field 10 is the     
       Then: lb="1"          'key for our summary          
 11  -------   -   -   -   -   -   -   -   -   -   -   -   
       ! If: 10 eq ""        'Do as you please for blank   
       Then: return          'keys ...                     
 12  -------   -   -   -   -   -   -   -   -   -   -   -   
LPSUM01! If: lb gt "1200"    'I guess we need to increase  
       Then: return          'our array capacity           
 13  -------   -   -   -   -   -   -   -   -   -   -   -   
       ! If: sumKEY(lb) eq "" or sumKEY(lb) eq 10          
       Then: goto GOTSUMM                                  
 14  -------   -   -   -   -   -   -   -   -   -   -   -   
       ! If:                                               
       Then: lb=lb+"1"; goto LPSUM01                       
 15  -------   -   -   -   -   -   -   -   -   -   -   -   
GOTSUMM! If:                                               
       Then: sumKEY(lb)=10 ; lx(220,*)=sumTXT(lb)          
 16  -------   -   -   -   -   -   -   -   -   -   -   -   
       ! If:                                               
       Then: ly(12,.2)=mid(lx,"13","12")                   
 17  -------   -   -   -   -   -   -   -   -   -   -   -   
       ! If:                 'Assuming that field 100 is   
       Then: ly=ly+100       'total sale amount            
 18  -------   -   -   -   -   -   -   -   -   -   -   -   
       ! If:                                               
       Then: sumTXT(lb)=10&"  "&ly                         
 19  -------   -   -   -   -   -   -   -   -   -   -   -   
       ! If:                                               
       Then: return                                        
 20  -------   -   -   -   -   -   -   -   -   -   -   -   
@wbrk1 ! If: '/** This is the subtotal break where the     
       Then: '/** summary information will be printed      
 21  -------   -   -   -   -   -   -   -   -   -   -   -   
       ! If:                                               
       Then: clear prtTXT ; la="1"; lb="1"                 
 22  -------   -   -   -   -   -   -   -   -   -   -   -   
       ! If:                                               
       Then: gosub SUMMPRT                                 
 23  -------   -   -   -   -   -   -   -   -   -   -   -   
       ! If:                                               
       Then: clear sumKEY; clear sumTXT                    
 24  -------   -   -   -   -   -   -   -   -   -   -   -   
       ! If:                                               
       Then: end                                           
 25  -------   -   -   -   -   -   -   -   -   -   -   -   
SUMMPRT! If: la gt "1200"                                  
       Then: print ; return                                        
 26  -------   -   -   -   -   -   -   -   -   -   -   -   
       ! If: prtTXT(la) eq ""
       Then: print; return                                        
 27  -------   -   -   -   -   -   -   -   -   -   -   -   
       ! If: lb gt "26"                                    
       Then: print ; lb="1"; clear prtTXT                  
 28  -------   -   -   -   -   -   -   -   -   -   -   -   
       ! If:                                               
       Then: prtTXT(lb)=sumTXT(la); la=la+"1"; lb=lb+"1"   
 29  -------   -   -   -   -   -   -   -   -   -   -   -   
       ! If:                                               
       Then: goto SUMPRT                                   
 30  -------   -   -   -   -   -   -   -   -   -   -   -   


I think this should get the job done ... with no more than
2 or 3 glitches  8-)

Please notice that the above code was typed right off the
top of my head without testing or doing much review ... I
am simply intending to present you with a general idea as
to how this can be accomplished and not with the code that
will get the job done.  However, there is a chance that
that posted code could be used - Should you choose to do
so, be advise that you do it at your own risk and should
do due diligence.

Regards;


Jose Lerebours


More information about the Filepro-list mailing list