I have a table DataGrid which is using the GetDataForLine command. The script is below.
It queries an SQLite database of financial transactions.
I need to fill in the balance column in GetDataForLine as the balance is calculated for each transaction only for the selected records.
There seems to be something wrong with the calculation when pLine < gPrevLine and I am thinking it is something to do with the implementation of the DataGrid.
My script may be wrong but I have tried so many different options that my brain is now spinning.
Can someone please enlighten me as to where I am going wrong.
All suggestions welcome.
Thanks
Code: Select all
command GetDataForLine pLine, @pOutData
global gPrevLine,gPrevData
revMoveToRecord the uCursorID of this stack, pLine - 1 -- 0 based record navigation
put revDatabaseColumnNumbered(the uCursorID of this stack, 1) into tRowID
put merge("select date,type,description,amount,balance,category from '[[the uAcctName of this stack]]' WHERE rowid = [[tRowID]]") into tSQLStatement
set the uRowCursorID of this stack to revQueryDatabase(the uDB of this stack,tSQLStatement)
if the uRowCursorID of this stack is an integer then
put ConvertCurrentRowToArray() into pOutData
revCloseCursor the uRowCursorID of this stack
if pLine = 1 then
put pOutData["amount"] into pOutData["balance"]
put pOutData into gPrevData
put pLine into gPrevLine
end if
if pLine > gPrevLine then
put pOutData["amount"] + gPrevData["balance"] into pOutData["balance"]
put pOutData into gPrevData
put pLine into gPrevLine
end if
if pLine < gPrevLine then
put gPrevData["balance"] - gPrevData["amount"] into pOutData["balance"]
put pOutData into gPrevData
put pLine into gPrevLine
end if
end if
end GetDataForLine