Page 1 of 1

Checking for multiple values

Posted: Mon Oct 26, 2009 5:36 am
by phaworth
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

Posted: Mon Oct 26, 2009 6:14 am
by Janschenkel
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.

Posted: Mon Oct 26, 2009 7:23 am
by phaworth
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