Datagrid line check & delete.

Creating desktop or client-server database solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
gstone
Posts: 17
Joined: Wed Aug 19, 2015 4:19 pm
Location: United Kingdom
Contact:

Datagrid line check & delete.

Post by gstone » Fri Oct 23, 2015 10:23 am

Hello all,

I was hoping somebody could help with my current speed issues.

I have three datagrids all containing different sets of data, all have an identical column where if the value contains a certain number it will delete the line. My code is WIP but is doing what is asked of, just takes an average of around 55 seconds to complete, my goal time is between 10 - 15 seconds.

Here is an example of what i am currently working with:

Code: Select all

 --Line 1
   put the dgDataOfLine[1] of grp "DeliveryData" on Card "manifest" into tDataD
   put tDataD["item_status_ref"] into tDesiredValueD
   if tDesiredValueD >= 2 then
      put the dgText of group "DeliveryData" on Card "manifest" into myTempD
      delete line 1 of myTempD
      set the dgText of group "DeliveryData" on Card "manifest" to myTempD
   end if
this is then repeated 39 times as no loop created yet. So anything not equal to one delete the rows.

Any help would be really APPRECIATED :)

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Datagrid line check & delete.

Post by Klaus » Fri Oct 23, 2015 12:38 pm

Hi gstone,

OK, that is waaaaaaaay too long, we surely can get to under 1 second! :D
You are accessing and setting the dgtext of your group every time so it will last forever!

Here a repeat loop that will surely speed up things a bit.
Remember that "the dgtext of grp xyz" is "just" a TAB and CR delimited text list.

At what "position" (TAB ITEM number in the text) is that column?

Code: Select all

...
set itemdel to TAB
## replace X with the actual item number of your column "item_status_ref"
put X into tItemNumber
put empty into tNewData
put the dgText of grp "DeliveryData" into tData

## Here the repeat loop
repeat for each line tLine in tData

  ## We simply collect all lines that do NOT need to be deleted:
  if item < 2 then
    put tLine & CR after tNewData
  end if
end repeat

## get rid of trailing CR
delete char -1 of tNewData

## No write back to DG "en bloc"
set the dgtext of grp "DeliveryData" into tNewData
...
Try this, it may be a tad faster than before :D


Best

Klaus

gstone
Posts: 17
Joined: Wed Aug 19, 2015 4:19 pm
Location: United Kingdom
Contact:

Re: Datagrid line check & delete.

Post by gstone » Fri Oct 23, 2015 2:07 pm

Hi Klaus,

Now that looks like a great script! thanks for the quick reply. :D
The TAB Item number is number 5, which is all i need to extract in order to perform the deletions.

Thanks again for your help.

Gary

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Datagrid line check & delete.

Post by Klaus » Fri Oct 23, 2015 2:16 pm

Glad I could help! :D

Little typo in my script:
...
## We simply collect all lines that do NOT need to be deleted:
if item tItemNumber of tLine < 2 then
...

gstone
Posts: 17
Joined: Wed Aug 19, 2015 4:19 pm
Location: United Kingdom
Contact:

Re: Datagrid line check & delete.

Post by gstone » Fri Oct 23, 2015 2:20 pm

You have helped MASSIVELY :lol:

Just going to run the code now within the app. Exciting stuff.

PS: Thanks for the typo correction.

Post Reply

Return to “Databases”