Page 1 of 1
Delete an item
Posted: Tue Dec 22, 2015 5:55 am
by RossG
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.
Re: Delete an item
Posted: Tue Dec 22, 2015 12:15 pm
by Klaus
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
Best
Klaus
Re: Delete an item
Posted: Tue Dec 22, 2015 5:24 pm
by jacque
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
Re: Delete an item
Posted: Sat Dec 26, 2015 5:32 am
by RossG
Related, but different!
I have a field which displays a record number, tab, then a string of numbers thus:-
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.
Re: Delete an item
Posted: Sat Dec 26, 2015 9:46 am
by Dixie
assuming here that line 1 of fld 1 = 55 & tab & 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