Filter by Item

Creating desktop or client-server database solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
trailboss
Posts: 124
Joined: Sat Dec 13, 2008 4:55 pm

Filter by Item

Post by trailboss »

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
Klaus
Posts: 14325
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Filter by Item

Post by Klaus »

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
trailboss
Posts: 124
Joined: Sat Dec 13, 2008 4:55 pm

Re: Filter by Item

Post by trailboss »

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?
BvG
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1239
Joined: Sat Apr 08, 2006 1:10 pm
Contact:

Re: Filter by Item

Post by BvG »

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
Various teststacks and stuff:
http://bjoernke.com

Chat with other RunRev developers:
chat.freenode.net:6666 #livecode
Klaus
Posts: 14325
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Filter by Item

Post by Klaus »

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?! :shock:
Well, that's astounding (but rather unhealthy)! :D
trailboss
Posts: 124
Joined: Sat Dec 13, 2008 4:55 pm

Re: Filter by Item

Post by trailboss »

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
Klaus
Posts: 14325
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Filter by Item

Post by Klaus »

Hi Tom,

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
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
trailboss
Posts: 124
Joined: Sat Dec 13, 2008 4:55 pm

Re: Filter by Item

Post by trailboss »

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
Klaus
Posts: 14325
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Filter by Item

Post by Klaus »

De nada senor :)
Post Reply