November 10, 201312 yr 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.
November 10, 201312 yr 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 >> )
November 10, 201312 yr Author 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?
November 10, 201312 yr 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]
January 18, 201510 yr 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.
Create an account or sign in to comment