PDA

View Full Version : sum in foxpro report


sge
05-10-07, 05:22
Hello,
i want to make a normal report

1. jan feb mar
2. jan feb mar
-------------
SUM of jan feb mar

The last line is - normally - no problem with foxpro (Properties, calculation type SUM).
But now I need to colour it red, when the sum is <0
I tried to do it with the property "PRINT WHEN jan<0"
But then he checks the last value of jan (in the above example: 2. line)
When I try "PRINT WHEN sum(jan)<0" the error message appears "canīt find sum.prg".

How can I do it???
Thanks for any help!!!

sge

georgev
05-10-07, 05:54
Can you use procedures?

Local MyVariable

MyVariable = sum(jan)
Do Case
Case MyVariable = 0
....
Otherwise
...
End Case

It's hard to find a solution here without knowing more about the problem.
Is sum(jan) a calculated field?
If so, what is the name of the field it is calculating the sum of?

I doubt the above will work, but give it a try :)
(it's been a while since I did reports in VFP!)

sge
05-10-07, 06:32
Its a table with following structure

text jan feb mar
xx 30 31 32
yy 20 21 22
zz -10 11 12

and just a normal foxpro report:source is the above table with all fields
and a footer row with the sum of each column. The designer looks like this:

Detail
<text><jan><feb><mar>
Footer
"SUMME"<jan><feb><mar> <- each with the properity calculation type SUM

And the report looks like this:
xx 30 31 -32
yy 20 21 -22
zz -10 11 12
---------------------
SUMME 40 63 -42


Now I want to have black colour when sum is >0 (40 and 63) and red when sum <0 (-42).
I added the property PRINT WHEN jan(/feb/mar)>0 to each sum field and added three new sum fields with colour RED, properity calculation type SUM and property PRINT WHEN jan(/feb/mar)<0. So the footer looks like

"SUMME" <jan> calculation type SUM,colour black,PRINT WHEN jan>0
<jan> calculation type SUM,colour red,PRINT WHEN jan<0

Result is: 40 red , 63 black(ok), -42 black
because the PRINT WHEN looks at the last row of the detail part:
-10 is <0 => 40 is red
12 is >0 => -42 is black

When I say PRINT WHEN sum(jan)>0 => error: sum.prg not found

Is there any simple solution or have I to write my own sum.prg?

georgev
05-10-07, 07:39
PRINT WHEN empty(sum(jan)) ?

sge
05-10-07, 08:06
The problem is: he does not understand SUM in PRINT WHEN!!!

georgev
05-10-07, 09:15
Who's "he" ? :p

And no need to ge irate mate, I'm just throwing stuff into the pool and seeing if it floats.

Can you reference the textbox through code? Eg

If Textbox0.value = 0
Textbox0.forecolor = ...
EndIf

Or something similar? Let's step away from PRINT WHEN for a moment and think of a new approach.