Checking for multiple values

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
phaworth
Posts: 592
Joined: Thu Jun 11, 2009 9:51 pm

Checking for multiple values

Post by phaworth » Mon Oct 26, 2009 5:36 am

If I want to check for the presence of one of several values in a variable, is it OK to do something like:

if variable contains "ABC" or XYZ" then ....

Pete

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Location: Aalst, Belgium
Contact:

Post by Janschenkel » Mon Oct 26, 2009 6:14 am

Nope, you'll have to spell them out as independent contains comparisons. One options is something like this:

Code: Select all

put "ABC,XYZ" into tContainCriteria
repeat for each item tContainCriterion in tContainCriteria
  if variable contains tContainCriterion then
    -- do your thing
    exit repeat
  end if
end repeat
This approach is dynamic, in that you can easily extend the criteria to whatever length suits you; and the exit repeat ensures that your code is only called once.

HTH,

Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

phaworth
Posts: 592
Joined: Thu Jun 11, 2009 9:51 pm

Post by phaworth » Mon Oct 26, 2009 7:23 am

Thanks Jan, I thought that was the case. I had something like what was in my original post and it didn't throw a compilation error but didn't appear to be working.
Pete

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”