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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perform while/if loop based on 2 month parms

Status
Not open for further replies.

jimdena33

Programmer
Sep 20, 2008
5
US
Perform while/if loop based on 2 month parms to sum certain columns.

I need Crystal syntax for a formula(s) to do a psudeo Perform while/if loop based on 2 month parms to sum certain columns..................

I have 2 run parameters for the beginning month number and another for the ending month number.

I then pass these 2 values to a subreport.

The subreport then needs to sum columns that are named number01.........number12 based on the values of the beginning and ending month numbers.

The challenge is how to write the formula so that I don't have every known mathematical combination of 01 thru 12, 02 thru 12, 06 thru 07, etc.... and somehow spin through the parm ranges related to the columns suffix name.

Is there some type of while and IF logic that I could use and how would I have a variable on the column name?

While
If number(##) in range of beginning month number and ending month number sum each qualifying column;

(where ## = the column's 2 character suffix)
Do I have to build other formula's to represent each column as some variable?

Your help is much appreciated. Thank you.
 
They key problem is that you can't treat a field name as a variable. So you need to put the fields into an array first.

//store the fields in an array
Local Numbervar array myList := [{table.field01},
{table.field02},{table.field03},{table.field04},[table.field05},{table.field06},{table.field07},{table.field08],{table.field09},{table.field10},{table.field11},{table.field12}];

//load parameter values into local variables
Local numbervar firstcol:={?firstcol};
local numbervar lastcol:={?lastcol};

//check parameters are valid within the range
if firstcol < 1 then firstcol:=1;
if lastcol > count(mylist) then lastcol := count(mylist);
if lastcol < firstcol then lastcol:= firstcol;

local numbervar i;//counter for loop
local numbervar coltotal:=0; //accumulator

for i:= firstcol to lastcol do
coltotal := coltotal + mylist ;

//display accumulator
coltotal


Editor and Publisher of Crystal Clear
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top