Filter by Item
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Filter by Item
I'm working on my super smokin' bird database and I need to filter by item. I want to say filter this without item 3 of myvar, but I can't remember how to do it. I can filter by strings, but if someone told me how to filter out an item in my data, I can't remember. Thanks!
Tom in Arizona
Tom in Arizona
Re: Filter by Item
Hi Tom,
I am not sure if I understand you correctly, but simply make that var a string like:
...
put item 3 of myvar into string2filter
filter whatever without string2filter
...
Or simply use the var as a string:
...
filter whatever without (item 3 of myvar)
...
Best
Klaus
I am not sure if I understand you correctly, but simply make that var a string like:
...
put item 3 of myvar into string2filter
filter whatever without string2filter
...
Or simply use the var as a string:
...
filter whatever without (item 3 of myvar)
...
Best
Klaus
Re: Filter by Item
Well, you see, I have records like this with four items and I want the fourth one to go take a powder.
BIRDNAME,DATE,PLACE,NOTE
I HAVE:
Common Snipe,01/22/2010,Lonely Mountain,A nice big one with a chocolate back
American Robin,01/31/2010,Phoenix Sewer Flats,Unusual bird for the Phoenix area. Everyone was pretty interested to see this as it usually rears its head only in high-altitude regions of the state. The last in-town robin was a six years ago and in my own backyard! Don't expect to see one again soon.
I WANT:
Common Snipe,01/22/2010,Lonely Mountain
American Robin,01/31/2010,Phoenix Sewer Flats
The note item is wordy and its endless verbiage conflicts with other sorts and filters. I don't want to diddle with the notes all the time.
If I do it by string, only item 4 of record 1 goes away as every note is different.
I need a code like "Wipe out item four!" Perhaps filtering is only for specific strings?
BIRDNAME,DATE,PLACE,NOTE
I HAVE:
Common Snipe,01/22/2010,Lonely Mountain,A nice big one with a chocolate back
American Robin,01/31/2010,Phoenix Sewer Flats,Unusual bird for the Phoenix area. Everyone was pretty interested to see this as it usually rears its head only in high-altitude regions of the state. The last in-town robin was a six years ago and in my own backyard! Don't expect to see one again soon.
I WANT:
Common Snipe,01/22/2010,Lonely Mountain
American Robin,01/31/2010,Phoenix Sewer Flats
The note item is wordy and its endless verbiage conflicts with other sorts and filters. I don't want to diddle with the notes all the time.
If I do it by string, only item 4 of record 1 goes away as every note is different.
I need a code like "Wipe out item four!" Perhaps filtering is only for specific strings?
-
- VIP Livecode Opensource Backer
- Posts: 1236
- Joined: Sat Apr 08, 2006 1:10 pm
- Location: Zurich
- Contact:
Re: Filter by Item
repeat for each line theLine in yourText
put item 1 to 3 of theLine & return after theResult
end repeat
delete char -1 of theResult --last return
put item 1 to 3 of theLine & return after theResult
end repeat
delete char -1 of theResult --last return
Various teststacks and stuff:
http://bjoernke.com
Chat with other RunRev developers:
chat.freenode.net:6666 #livecode
http://bjoernke.com
Chat with other RunRev developers:
chat.freenode.net:6666 #livecode
Re: Filter by Item
Ah, sorry, obviously I misunderstood you completely...
Björnkes solution fits well to your needs.
Best
Klaus
P.S.
You have smoking birds over there in Arizona?!
Well, that's astounding (but rather unhealthy)!
Björnkes solution fits well to your needs.
Best
Klaus
P.S.
You have smoking birds over there in Arizona?!
Well, that's astounding (but rather unhealthy)!
Re: Filter by Item
Thanks for the help. I can't get that script to do anything. I guess it's my inexperience. It's just a repeat, isn't it? I tried this:
on mouseUp
set cursor to watch
put 1 into lineo
put card fld sortfield into yourtext
repeat with i = 1 to the number of lines of yourtext
put item 1 to 3 of line lineo of yourtext into theresult
put theresult into line lineo of newlist
put lineo + 1 into lineo
end repeat
put newlist into cd fld sortfield
end mouseUp
It works, but I have more than 20,000 birds to sort. That's 20,000 lines, so it takes forever. Filtering, when it can be used, is super fast.
Tom
on mouseUp
set cursor to watch
put 1 into lineo
put card fld sortfield into yourtext
repeat with i = 1 to the number of lines of yourtext
put item 1 to 3 of line lineo of yourtext into theresult
put theresult into line lineo of newlist
put lineo + 1 into lineo
end repeat
put newlist into cd fld sortfield
end mouseUp
It works, but I have more than 20,000 birds to sort. That's 20,000 lines, so it takes forever. Filtering, when it can be used, is super fast.
Tom
Re: Filter by Item
Hi Tom,
if possible avoid "repeat with x = ..." and use "repeat for each..." like this:
When using "repeat with..." the engine will count the lines in the loop, wehn using "repeat for each..."
it does not, that's why this is insanely fast. Please test it by yourself
Best
Klaus
if possible avoid "repeat with x = ..." and use "repeat for each..." like this:
Code: Select all
on mouseUp
set cursor to watch
put fld sortfield into yourtext
repeat for each line tLine in yourtext
put item 1 to 3 of tLine & CR after newlist
end repeat
## Delete trailing CR
delete char -1 of newlist
put newlist into cd fld sortfield
end mouseUp
it does not, that's why this is insanely fast. Please test it by yourself
Best
Klaus
Re: Filter by Item
Klaus,
Thanks so much. It's like greased lightning! Why hasn't anyone told me this? My repeat takes AGES -- I mean ages! Yours is instantaneous with 20,000 lines. I have some scripts that make me wait that I can fix now.
¡Mil gracias!
Tom
Thanks so much. It's like greased lightning! Why hasn't anyone told me this? My repeat takes AGES -- I mean ages! Yours is instantaneous with 20,000 lines. I have some scripts that make me wait that I can fix now.
¡Mil gracias!
Tom
Re: Filter by Item
De nada senor