Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

order of eval for case statements

Featured Replies

once a test in a case statement is true, will filemaker do the result and quit trying the other cases, or do I have to worry about having multiple true cases?

  • Author

Thanks, that's what I figgured it would do, but you never know how any given language and or compiler will implement the case.

True. Watch out for those Case statements that stop just before getting to the true condition. smile.gif

Q: Does this bus stop on Main Street?

A: Yes ma'am. Just watch me, and get off one stop before I do.

  • 8 months later...

BobWeaver said:

It stops after the first true case.

hmm, does it really? I tried this formula:

case(NOT switch, "0", sum(relation::number))

where "switch" is a global number and "relation::number" is a unstored calculation in a relation db with 100'000 records.

if "switch" has the value "1", the sum will be evaluated and I have to wait about 5 seconds until FM has done. So far so good. smile.gif

If "switch" has the value "0", the condition becomes true and FM should not evaluate the heavy relation. BUT IT DOES! The result is 0 (correctly), but the time to evaluate the result is AGAIN 5 seconds. frown.gif

Am I missing something?

Gerd

All the evidence I've seen points to the contrary. As you noticed, Gerd, it takes the same amount of time to process a Case(), regardless of which result it produces. It also apparently uses the same amount of memory.

I'm nothing of an expert, but I assume calculations are far different from scripts although the FileMaker way of thinking may let us a little bit confused about that.

Scripts are made of steps among which a few are crossroads. Calculations are entities that have to be evaluated as a whole. Scripts can be exited, calculations cannot.

Maybe some geek could discuss this.

Yet the most important is that the result is correct.

True, but scripts rely on If() and End If steps, which is far different from a Case() or If() calculation. And Case() can be used in If() steps, yet it still fully evaluates each result before continuing, and there isn't much point in doing that anyway.

I should point out that in my earlier answer, I wasn't addressing the question of whether Filemaker evaluates the entire expression or not. I only meant that if more than one condition is true, then the result that is returned is the one corresponding to the first true condition. It's quite possible that FM continues to evaluate all remaining conditions of the expression even after it finds a true one.

One good trick for moving along case statements is the PatternCount function. You can have

Case(

Text="True", "Yay!",

Text="Lie", "Boo!!",

(PatternCount(Text,"True")>0) AND (PatternCount(Text,"Lie")>0), "You're confusing me!!!",

"")

This will stop on the first case if you type "True", but keep going if you wrote "True Lies", whereas if they were all PatternCounts it would stop at the first one for either entry. And if they were all "=" it wouldn't use any of them. You can do this for non-text fields, too, especially if you convert them to text first.

Ah, good point. I had to reread the question a few times before I saw what he was really asking. Thanks for clarifying.

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.