DataGrid GetDataForLine

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: Klaus, FourthWorld, heatherlaine, robinmiller, kevinmiller

Post Reply
tellboy
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 50
Joined: Wed Mar 06, 2013 1:31 pm

DataGrid GetDataForLine

Post by tellboy » Wed Mar 06, 2013 1:42 pm

Hi,

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

tellboy
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 50
Joined: Wed Mar 06, 2013 1:31 pm

Re: DataGrid GetDataForLine

Post by tellboy » Wed Mar 06, 2013 3:53 pm

Here is a sample image
Screen Shot 2013-03-06 at 14.49.47.png
Screen Shot 2013-03-06 at 14.49.47.png (12.17 KiB) Viewed 608 times
As you can see 14489 + (-20) does not equal -236328.19.

This probably helps in understanding my script.

Thanks

tellboy
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 50
Joined: Wed Mar 06, 2013 1:31 pm

Re: DataGrid GetDataForLine

Post by tellboy » Wed Mar 06, 2013 4:15 pm

I think the issue might be that as you scroll the table the line asked for is not necessarily the next line in sequence thus this would throw out my script for a running total.

If this is the case how could I overcome the problem.

Even with a limited record set of say 1000 the delay in loading them directly into the DataGrid (not using GetDataForLine) is noticeable.

Any ideas anyone.

Thanks

Post Reply

Return to “Talking LiveCode”