13 Replies Latest reply on Jan 18, 2010 5:56 AM by ninja

# If , And, Case Statements

### Title

If , And, Case Statements

### Post

does anyone know of a good read or a good example file to better explain how the If and  case statments work? for my database its very important i learn to use this, i used it alot in .net programing but it seems to be a tad different here in filemaker.

• ###### 1. Re: If , And, Case Statements

Google "case statement vs if statement filemaker"

• ###### 2. Re: If , And, Case Statements

thumper wrote:
does anyone know of a good read or a good example file to better explain how the If and  case statments work?

Have you read the help on these functions?

• ###### 3. Re: If , And, Case Statements
yes guys i know how to google and i did read the help, i was just wondering if some there were some reads which explain things in a different way. im still having trouble understainding in some ways.
• ###### 4. Re: If , And, Case Statements

=============

Case vs If

http://www.jamesng.com/filemaker/filemaker_quick_tips/index.shtml

Tip 2: Case versus IF Statements
Case statements were introduced in version 3.0 of FileMaker. They perform exactly function as an If statement, however can greatly simplify calculations. Case statements are best used in place of a nested If statement. This is best illustrated by examining two calculations which will return a number in words (in the calculated field Display), based on a numeric entry (in the field Number) Using an If statement: If(Number = 1, "One", If(Number = 2, "Two", If(Number = 3, "Three","")))
Using a Case statement
Case(Number = 1,"One", Number=2, "Two", Number=3,"Three")

FILEMAKER: Nested If Statements Vs Case Statements

http://dwaynewright.blogspot.com/2008/10/filemaker-nested-if-statements-vs-case.html

If ( test; resultOne; resultTwo )

http://www.fmforums.com/forum/showtopic.php?tid/193938/

===============

Was there something specific you were looking for?

• ###### 5. Re: If , And, Case Statements

If is for yes or no.

Case is for multiple conditions.

For example:

If(fieldA = "abc" ; "123" ; "456")

This means, if fieldA contains the text abc, then return 123, all other times, return 456.

If you have multiple conditions use case:

Case(

fieldA = "abc" ; "123";

fieldA = "def" ; "456";

fieldA = "xyz" ; "789";

"654"

Notice the last one is all by itself. If the three conditions above it are not met, all others will return 654. You can leave out the last one as well and it will still work. Cheers.

• ###### 6. Re: If , And, Case Statements

The only reason I see for using if statements these days, is when they are used as a script step

As far as I am aware, both methods (if and case) 'short circuit' so to speak when a condition is true

So I don't believe there are any speed benefits..  but correct me if Im wrong on this...

• ###### 7. Re: If , And, Case Statements

NO

QUOTE deltatango

If is for yes or no.

Case is for multiple conditions.

/QUOTE

Nested IF statements allowed for multiple conditions.

Case is more elegant and less confusing.

Nested IF statements with Case Arguments are rare

but allow more complexities.

• ###### 8. Re: If , And, Case Statements
the guy is looking for a simple answer. let's all make it 10x more complicated for him please.
• ###### 9. Re: If , And, Case Statements

the guy is looking for a simple answer. let's all make it 10x more complicated for him please

The simple question presupposing the simple answer?

There is an ample amount of flailing about due to incomplete or inaccurate questions, due to inexperience, language differences, and experience differences.

• ###### 10. Re: If , And, Case Statements
SW wrote:

"The only reason I see for using if statements these days, is when they are used as a script step"

The If FUNCTION and the If SCRIPT STEP are different animals. I point this out not to correct you, but since I've witnessed confusion over this issue on the part of novices, to clarify this in the hope of avoiding confusion.

RW

• ###### 11. Re: If , And, Case Statements

So, we are all agread that the docs and conventionial wisdom is lacking on this subject?

The best prospect for all to be satisfied is a logical and easily followed howto?

What is that howto? Where is it to found? If it does not exist, can it be created?

• ###### 12. Re: If , And, Case Statements

David Anders :"So, we are all agread that the docs and conventionial wisdom is lacking on this subject?"

Perhaps . . . I find the documentation of FM functions to be pretty good for what it is and I've learned much of what I know from the docs. One aspect of functions that's hard to grasp when starting is exactly how specific they are. A person really has to have momentary "tunnel vision" to focus on what a function does, and more importantly, what it doesn't do. Examples are important, but then again there are several sites with example functions available on line. That said, I remember spending a lot of time and energy trying to understand them and it might have been easier with more material around . . . I still have a hard time getting my head around certain functions and combinations. But perhaps all that work isn't such a bad thing? You're obviously quite experienced in this field. I have limited but solid (I believe) knowledge of DB tech. I'm not sure I'd have the tools to teach anyone 'tho.

Interesting . . .

RW

• ###### 13. Re: If , And, Case Statements

SW wrote:

The only reason I see for using if statements these days, is when they are used as a script step

As far as I am aware, both methods (if and case) 'short circuit' so to speak when a condition is true

So I don't believe there are any speed benefits..  but correct me if Im wrong on this...

Howdy SW,

Just an FYI...there is actually a slight speed benefit, at least in one particular calculation that's been posted, but it isn't a script looking for 'true' as you comment on.

Not MAX, Not MIN, Not AVG - 'Middle' of 3 values

The speed benefit is so slight, however, that I have never been in a position to notice it myself.