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.

Help with syntax (and good books)

Featured Replies

Hi,

I need help with a case statement (at least that's what I think I should use).

I'm collecting student test results. I want to assign a total mark based on the total of some other assignments. If the total of the assignments falls between a certain range they get one mark, between other ranges then other marks should be assigned.Marks can be 1, 2, 3, 0r 4

Not sure about the syntax though.

I want it to say:

Term1Score =

In the case that: (T1Total is >= 5 and <=13 then assign a mark of 1) or (T1Total is >=14 and <=22 then assign a mark of 2) or (T1Total >=23 and <=29 then assign a mark of 3) or (T1Total >=30 and <=36 then assign a mark of 4) or if all of these tests fail, then assign a mark of 0

If you can help me to sort this out, I'd sure appreciate it.

Thanks,

Paul

P.S. Can you recommend any good how to FMP books for beginners.

The case statement works in pairs until you get to the last part, which is your default result should should all the other tests have failed.

Case (T1Total >= 5 and T1Total <= 13, 1, T1Total >= 14 and T1Total <= 22, 2, T1Total >= 23 and T1Total <= 29, 3, T1Total >= 30 and T1Total <= 36, 4, 0)

Disclaimer: I just learned the "case" syntax on this forum a few days ago and have never used it!B)

--

Jason Wood

HeyWoody.com

  • Author

Thanks Jason,

That works well!

Paul

Case (T1Total >= 5 and T1Total <= 13, 1, T1Total >= 14 and T1Total <= 22, 2, T1Total >= 23 and T1Total <= 29, 3, T1Total >= 30 and T1Total <= 36, 4, 0)

That does exactly what was asked and will probably work fine... but the professional programmer in me always wants to make it shorter to type, easier to read, more efficient to run, and more bulletproof (e.g., what happens when you get a score of 29.5 someday in the future... or a bonus question is added and a student gets a 38... then the student gets a mark of zero [ouch])... I'd write:

Case(T1Total >= 30, 4, T1Total >= 23, 3, T1Total >= 14, 2, T1Total >= 5, 1, 0)

and that illustrates an additional property of Case... they are evaluated in order... so you can build on the fact that the previous tests must've failed.

  • Author

Didn't know that! That is great. Much appreciated.

kewl... I was wondering about that!

Thanks!

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.