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.

Is it possible to use a loop in a field calculation?

Featured Replies

I have a BASIC program to calculate sunrise and sunset times which I am trying to rewrite for FMA 8.5. So far, I have been able to create fields and global variables for the BASIC subroutines, but the main program calls a loop to evaluate the validity of data for each hour in the day,

As far as I can see, the only way to generate a loop is through scripting, and I think the complexity involved will make it quite difficult. Is there a way to create a loop by calculation or custom functions?

Here is the BASIC txt file and the code I have written so far. I'm not altogether certain what some of the individual calcs are doing, so I have done quite a bit of literal translation. Sorry it's so messy!

The loop can be found in the BASIC from lines 210 to 260. It calls a subroutine which I have not yet written...

thanks

Steve

sunup.txt

code.zip

Hey clive,

A partial answer for you: Yes, you can do looping through a custom function, but it's a recursive call instead of an iterative call like you have in your BASIC code.

I can't deconstruct your code, but to give you the idea, this is a simple recursive CF that adds the numbers in a specified range:

SumRange( from ; to ) =

Case(from <= to ; from + SumRange(from + 1 ; to))

Although CFs could be written in an iterative manner, sending loop control variables to each succeeding function call, it's generally preferable to control the loop by reducing the parameter(s) in each succeeding call. You know you're done when the parameter is empty or matches a stopping condition.

  • Author

This is neat, Ender. Thanks! I'll need to spend some time with it to get my head around it, but it does appear to be what I'm after.

Try This...

Regards,

INO :laugh2:

code_by_Ino.zip

  • Author

This is superb, Ino. Many thanks, and may I congratulate you on its elegance. I've done some checking, and your calcs give a result very close to the US Naval Observatory times. It's closer than my local newspaper! Certainly better than the 5-6 min error of the program I'd previously relied on.

Do you have similar calcs for the Moon and other planets? :D

Well I thought I had seen most requests but...

Do you have similar calcs for the Moon and other planets? :D

is one I never expected to see!!

Happy New Year everyone.

Phil

Thanks

Also if You can use Shell script in fmp You can grab formally any place (Longitude and Latitude) on The Earth and calculate real Sunset & Sunrise.

Not calculations for other planets (You can find it on Javascript examples which you can implemented with HTML sheet and use thru Web Viewer - but I’m not so familiar with HTML & Javascript so ...) , something for moon phase (position of moon for day).

If You have some other questions You can call me on Skype (zagino) or send me an e-mail.

Pls. don’t forget I am UTC (GMT) +1 Time - CET.

regards

Ino

My vote goes to this one.

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.