Delete an item

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
RossG
Posts: 247
Joined: Thu Jan 08, 2015 7:38 am

Delete an item

Post by RossG » Tue Dec 22, 2015 5:55 am

I have a variable theString with numbers "4,6,21,3,32..." etc.
and a variable tVar with numbers "1,2,3,4....36"

I want to loop through the numbers in theString and delete the
same number from tVar...

repeat with m = 1 to 36
put m & "," after tVar
end repeat

repeat for each item theItem in theString until the number of items in tVar < 11
if theItem is among the items of tVar then
---delete item .....
end if
end repeat

I've tried a number of ideas for the line ---delete item etc. but all so far all delete item number
theItem and not the number.

A curious thing: one of the variations I tried delete the line of code!!!

Help appreciated.
Is age an excuse? Eighty-four and counting.
Programming powered by coffee.

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Delete an item

Post by Klaus » Tue Dec 22, 2015 12:15 pm

Hi Ross,

try again but use:
-> itemoffset
and first
-> set the wholematches to true

Because 4 is in 4,14,24 and 34!
You get the picture :D


Best

Klaus

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Delete an item

Post by jacque » Tue Dec 22, 2015 5:24 pm

Code: Select all

repeat for each item theItem in theString until the number of items in tVar < 11
You can't combine "repeat for each" and "repeat until" structures. Do this instead:

Code: Select all

repeat for each item theItem in theString
    if the number of items in tVar < 11 then exit repeat 
    .... 
end repeat 
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

RossG
Posts: 247
Joined: Thu Jan 08, 2015 7:38 am

Re: Delete an item

Post by RossG » Sat Dec 26, 2015 5:32 am

Related, but different!

I have a field which displays a record number, tab, then a string of numbers thus:-

Code: Select all

55    1,2,3,12,17,23,32, 
I want to delete a line in which a number appears e.g if aNumber is 3 I want to
delete this record from the field.

My efforts so far falls over because the "55" isn't an item (or some other reason?)

Help appreciated.

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: Delete an item

Post by Dixie » Sat Dec 26, 2015 9:46 am

assuming here that line 1 of fld 1 = 55 & tab & 1,2,3,12,17,23,32

Code: Select all

55	1,2,3,12,17,23,32
The line is tab delimited, so item 1 of the line = 55 and item 2 of the line = 1,2,3,12,17.23.32...
To get at the items of item 2 of the line, change the itemdel to comma...

to delete a number from the record...

Code: Select all

on mouseUp
   put line 1 of fld 1 into tempRecord
   set itemDel to tab
   put item 2 of tempRecord into tempVar
   set itemDel to comma
   
   repeat with count = 1 to the number of items of tempVar
      if item count of tempVar = 3 then
         delete item count of tempVar
      end if
   end repeat
   
   put tempVar
end mouseUp
or delete the whole record if the number 3 appears anywhere in the record

Code: Select all

on mouseUp
   put line 1 of fld 1 into tempRecord
   set itemDel to tab
   put item 2 of tempRecord into tempVar
   set itemDel to comma
   
   if 3 is among the items of tempVar then
      set itemdel to tab
      delete item 2 of tempRecord
   end if
   
   put tempRecord
end mouseUp

Post Reply