4 Replies Latest reply on Jan 13, 2013 2:00 PM by avallejo

# Scripting "if" with "or" or "and"...

### Title

Scripting "if" with "or" or "and"...

### Post

Hi all.

I'm trying to figure out how to make a simple script lke the one designed below, but I can't find in the reference material I found. Could someone please give me an example? I can make a simple "if +else" script, but the and-or part I can't make right...

tks,

André

If field A and field B and field C  = 0

then field Z = 0

Else, if any of the fields not 0

Then field Z = 1

• ###### 1. Re: Scripting "if" with "or" or "and"...

André, try this:

If [your_table_name::field A = 0 and your_table_name::field B = 0 and your_table_name::field C = 0]

Set Field[your_table_name::field Z ; 0]

Else

Set Field[your_table_name::field Z ; 1]

End if

Note: Fields must be type "Number"

• ###### 2. Re: Scripting "if" with "or" or "and"...

I will, thanks!

• ###### 3. Re: Scripting "if" with "or" or "and"...

...and that doesn't have to be a script step, from what you have described.  You could just make it a calculation field:

Case (

Field A = 0 and Field B = 0 and Field C = 0 ;

0 ;

1

)

I always prefer to use Case over If in a calculation.  And a calculation is generally better than setting field values by a script step, as the method is more reliable.

• ###### 4. Re: Scripting "if" with "or" or "and"...

Good to know! As I'm learning I'll try both ways so I can learn more!

best,André