open card and delete multiple grouped objects

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
jalz
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 340
Joined: Fri Sep 12, 2008 11:04 pm

open card and delete multiple grouped objects

Post by jalz » Tue Apr 22, 2014 12:47 am

Hi Guys,

I have a card, which contains multiple grouped objects called PurchaseLineX (x being the instance number). The thing is, I may have a card which contains only one PurchaseLine group, or I may have a card which could contain upto 30 PurchaseLine Groups. I'm trying to write some initialisation routine, which scans the card for any PurchaseLine groups and deletes them.

Anyone know of a simple way to achieve this, or is it more efficient if I delete the card and then recreate it with the header, footer information, before populating the data with the PurchaseLine information.

Thanking you in advance.
Jalz
Last edited by jalz on Tue Apr 22, 2014 9:23 am, edited 1 time in total.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10333
Joined: Wed May 06, 2009 2:28 pm

Re: ope card and delete multiple groups

Post by dunbarx » Tue Apr 22, 2014 1:09 am

Hi.

Code: Select all

on opencard
repeat with y = the number of groups down to 1
if the short name of group y contains "purchaseLine" then delete group y
end repeat
end openCard
Now how does this work? In other words, why count down instead of up? Do you see that we do not have to (though we certainly could) consider the number of each "purchaseLine" group, that we can use another "property" to identify them? In fact, why not rewrite this handler in a way that does indeed use the several "purchaseLine1, purchaeLine2, etc." group names. Consider that payment for the code snippet.

Write back with what you find.

Craig Newman

jalz
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 340
Joined: Fri Sep 12, 2008 11:04 pm

Re: open card and delete multiple grouped objects

Post by jalz » Tue Apr 22, 2014 10:00 am

Hi Craig,

That is awesome, does exactly what I want. I used the debugger to walk through and understand the code, added other grouped objects but without the same name, works bang on. Would not of thought counting up...

Thanks
Jalz

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: open card and delete multiple grouped objects

Post by Simon » Tue Apr 22, 2014 10:42 am

Hi Jalz,
why count down instead of up?
This will twist your brain!

Not really sure if I can explain it correctly, but why does this not work;

Code: Select all

on mouseUp
   put "delete me" & comma & "save me" & comma & "delete me" & comma &"delete me" into tTest
   repeat with x = 1 to the number of items in tTest
      if item x of tTest contains "delete me" then
         delete item x of tTest
      end if
   end repeat
   answer tTest
end mouseUp
and this does

Code: Select all

on mouseUp
   put "delete me" & comma & "save me" & comma & "delete me" & comma &"delete me" into tTest
   repeat with x = the number of items in tTest down to 1
      if item x of tTest contains "delete me" then
         delete item x of tTest
      end if
   end repeat
   answer tTest
end mouseUp
???

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

jalz
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 340
Joined: Fri Sep 12, 2008 11:04 pm

Re: open card and delete multiple grouped objects

Post by jalz » Tue Apr 22, 2014 11:30 am

Hi Simon,

Thanks for your snippet of code. I was really confused until I got into the debugger to see what was going on and of course its logical when you think about it and walk through your example....

Thanks
Jalz

Post Reply