Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Conditional IF with multiple choices

0 views
Skip to first unread message

drink

unread,
Oct 21, 2009, 11:40:04 AM10/21/09
to
How can I do an IF with multple correct choices such as

If variable = A | B | C | Z (which doesn't work for me)

with out saying

If variable = A | variable = B | variable = C | variable = Z ???

I have a long list of good choices.

Thanks

Captain Paralytic

unread,
Oct 21, 2009, 11:47:42 AM10/21/09
to

If you can think of a delimiter character that will never appear in
any of the strings (e.g. '00'x), then you can do:
del = '00'x
set = del || 'A' || del || 'B' || del || 'C' || del || 'D' || del
if pos(variable, set) > 0 ...

drink

unread,
Oct 21, 2009, 1:21:44 PM10/21/09
to

That is too slick!

Thanks. Works like a champ.

Captain Paralytic

unread,
Oct 21, 2009, 5:04:15 PM10/21/09
to

Actually, it should be slightly improved. I missed a bit:
=====================================


del = '00'x
set = del || 'A' || del || 'B' || del || 'C' || del || 'D' || del

if pos(del || variable || del, set) > 0 ...
=====================================
Whilst the original is fine if the values are really single characters
(in which case the delimiters are not needed), it will give false
positives if the variable can be a substring of any of the possible
values. This fixes that. I just forgot to put the delimiters in the
pos call.

drink

unread,
Oct 23, 2009, 2:58:09 PM10/23/09
to
> pos call.- Hide quoted text -
>
> - Show quoted text -

Thanks, that closes a small hole which I have now updated my code to
reflect.

wjensen_1

unread,
Oct 26, 2009, 1:42:18 PM10/26/09
to
If we talking about descrete strings, which seems to be the case, then
I would use the WORDPOS function, i.e.

if wordpos(translate(variable),'A B C Z')>0 then .....

The translate is there to ensure that a uppercase-to-uppercase
comparison is done.

Willy

0 new messages