Question : Fox 9    and reports creating Variables

A HAPPY 2010  TO ONE AND ALL     THANK YOU FOR ALL THE HELP YOU HAVE GIVEN ME !!!!

I am designing a report where I want to call on variables that I create which are derived from values found in tables. In the report menu  under variables where variable are born the system wont allow  to access records in tables. This is grayed out.  I would want something like   the variable x to = average cost between march of 2009 and june of 2009 etc from the table  tablename.  I try something like --in the expression box--   x=Average(tablename.cost) for year(date)=2009 .and. Month(date)>=3 .and. month(date)<=6     I would than use the variable X in other expressions.

But it wont recognize the table  even though I have it included in the data envornment of the form.


D

Answer : Fox 9    and reports creating Variables

Report variables are used for calculations or subtotals storing during the report execution. Values stored into report variables should be calculated from the main report table or tables in relation with this main report table. (Main report table is the one which is used for data output in report detail band.)

You cannot set additional conditions when calculating report variables because the record scope used for calculation is given by the record scope used in REPORT FORM command. Of course, you can use IIF() when calculating report variables.

I don't understand what is grayed out. If you define the variable name first then you may define expression for initial value, expression for value to store in each reported record etc. You may call UDF from this expressions and in this UDF you may calculate whatever you need.

If you need to calculate something "outside" the reported table then you should calculate it before the report run and store it to the standard VFP variable. Such variable can be printed out as any other data.

If you need to store some average to variable X as described in your question:
x=Average(tablename.cost) for year(date)=2009 .and. Month(date)>=3 .and. month(date)<=6

then you should do it prior the report run:

SELECT tablename
PRIVATE x
AVEARGE cost TO x FOR year(date)=2009 .and. Month(date)>=3 .and. month(date)<=6
*-- and now the X variable is available for the successive report.
SELECT MainReportTable
REPORT FORM ....  FOR ...
etc.

If you could post the report sample or its printscreen and better explain what to calculate and where then we may help better.
Random Solutions  
 
programming4us programming4us