Jump to content
Server Maintenance This Week. ×

how to write switch statement similar to c++/java/c# in FM ?


This topic is 3387 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Hi all,

 

I want to write couple of complex statements like following : 

switch (day % 31) {
                            case 0:
                                month = (day / 31);
                                day = 31;
                                break;
                            default:
                                month = (day / 31) + 1;
                                day = (day % 31);
                                break;
                        }
//above code is in java
but I coudn't find any way in FM to make me able to do such. All I know in FM is a very simple case something like :
result = Case (test1;"result here";test2;"result 2 here";"default result);
I want to do something like :
Case ( 0 ; "month = (day / 31);day = 31;" ; "month = (day / 31) + 1;day = (day % 31)";
 
Actually I want to do some calculation before returing result and I want to do it inside case.
Is there any way to do such in FM?
 
 
Thanks in advance.
Link to comment
Share on other sites

IMHO, your problem is not with the Case() function, but with variables. The Case() function can return only a single result. In Filemaker, you need to use the Let() function in order to assign variables, and these live only within the scope of the Let() function (unless you make them persistent by prefixing them with $ or $$ - which is not recommended, because then their scope exceeds the scope of the calculation). Note that the Let() function too returns only a single result.

 

There is no result in your example, so it's difficult to say what's the best route to proceed. Here's one possible construct out of several that come to mind:

Let ( [
test = Mod ( day ; 31 ) ;
month = day / 31 + GetAsBoolean ( test ) ;
day = Case ( test ; test ; 31 )
] ;
<< some formula using month and day comes here >>
)
Link to comment
Share on other sites

Thanks for the response, my problem is not return only a single value but how to have multiple statements inside case?

can you show me how to convert following java into FM :

if (date <= 186) {
switch (date % 31) {
case 0:
month = date / 31;
date = 31;
break;
default:
month = (date / 31) + 1;
date = (date % 31);
break;
}
year = miladiYear - 621;
} else {
date = date - 186;

switch (date % 30) {
case 0:
month = (date / 30) + 6;
date = 30;
break;
default:
month = (date / 30) + 7;
date = (date % 30);
break;
}

I am java developer but I couldn't figure it out how to convert these above lines into FM functions.

One more thing I saw FM has two types of programming, functions and scripts. Seems inside scripts we can have proper if/else and switch case is it so? or do I get it wrong?

Link to comment
Share on other sites

I am afraid your last example is just like the previous one - it doesn't do anything other than set (multiple) variables for some future use, presumably by some other calculation.  As I said earlier, in order to do this in Filemaker the variables would have to be persistent - and I cannot in good conscience recommend you go that way.

 

 

Inside a script, the only relevant difference is that the local $variables do expire when the script exits, so that you can have something like the following without worrying about leaving "residue" variables.

Set Variable [$day ; << some form of input >>]
...
If [ Mod ( $day ; 31 )]
 Set Variable [$month ; $day / 31 + 1]
 Set Variable [$day ; Mod ( $day ; 31 )]
Else
 Set Variable [$month ; $day / 31]
 Set Variable [$day ; 31]
End If
...
# later in the same script:
Set Variable [$result ; << some formula using $month and $day >>]
Exit Script [$result]
  • Like 2
Link to comment
Share on other sites

  • 1 year later...

Thanks for the response, my problem is not return only a single value but how to have multiple statements inside case?

can you show me how to convert following java into FM :

 

I agree with Comment regarding multiple return values.

 

It appears you are trying to mess around with Lunar -> Gregorian calendars here.

 

A way to drop this into one return value would be to use an actual Date type.  FileMaker's Date type is very smart, so you can start with say, 1/1/2000, add 300, and it will give you the correct month and day for the year 2000, taking into account leap years, days per month, etc.

 

If you were using that, I suspect a lot of this complexity would just drop away.

 

I suspect if you had some base lunar Date converted to a FM Date, you could use that to give you a delta to compute any Lunar <-> Gregorian conversion you wanted.

  • Like 1
Link to comment
Share on other sites

This topic is 3387 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

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