>>Stephen's suggestion is a way. Second adding a "calculated column" is another way.
>
>Re: "adding a "calculated column." Are you referring to a calculated field in the SQL field list? That would be a nice solution. I started to write a UDF which runs an SQL select to calculate the sum of all detail items up the current one but I haven't tried it yet. Is this what you are imagining?
SQL field list ? If you mean the original data was collected via SQL yes can be with some modification. ie:
select credit, debit, 0*0xFFFFFFF as balance ;
from mytable ;
into cursor grdCursor ;
nofilter
A scan...endscan would fill the balance (I think easier to do than designing a UDF for select). This way in grid for 1st and 2nd columns you would add some lostfocus code (and gotfocus to save value before change - assuming you're not performing tableupdate()) to replace "balance".
>
>I also thought about a sub-select to do the same thing but I couldn't see any way to do this.
>
>
>
>>Stephen's suggestion is better IMHO because you initialize the values once via a scan..endscan and change only the records that are current and below in the grid as credit or debit changes.
>
>The problem I have with Stephen's approach is that it puts unsaved data into a table buffer. (Unless I'm missing something.) Seems error prone.
>
This approach is still better IMHO. Buffered data is not SQL selected in calculations true. But you wouldn't need it.
- Scan ... endscan at entry.
- If credit or debit changes calculate difference (delta) for row.
- Add delta value to all balance from current rec to bottom.
(replace balance with balance+delta rest)
- Return to row.
This approach works fast even in FP2x :)
>Thanks for thinking about this.
>
>Peter
If not solved by monday I could send a ready example (don't remember where it's for the moment).
Cetin