April 21, 200223 yr What is the equaviliant of doing an Else If in FM. Most programming Setups you can do a If ElseIf ElseIf Else etc. I don't see that. Thanks -j
April 21, 200223 yr In scripts, its the If, Else, EndIf series. These can be nested, for example: code: if(Name = "Fred") .do freds stuff Else .if(Name = "Bill") ..do bills stuff .Else ..do the don't recognise the name stuff .EndIf EndIf In a calculation the same nesting rules apply, for example: code: NameRecognition = if(Name="Fred","HI Fred",if(Name="Bill","Hi Bill","Never heard of you")) Russ [ April 21, 2002, 02:00 PM: Message edited by: Russell Baker ]
April 21, 200223 yr Author Thanks. That works. Just wish there was a cleaner way. Get's confusing when you're 5, 6, 7, levels deep. -j
April 22, 200223 yr The only thing I can offer you to de-confuse it, is to write it this way in a calculation. code: if(Name = "Fred", "Hi Fred", if(Name = "Bill", "Hi Bill", if(Name = "Karen", "Hi Karen", if(Name = "Sam", "Hi Sam", if(Name = "Mike", "Hi Mike", if(Name = "Sue", "Hi Sue", "Never heard of you")))))) At least that way you can see what your choices are on a separate line, and then have your final choice if no condition is met on the last line followed by all the parenthesis. Russ [ April 21, 2002, 06:36 PM: Message edited by: Russell Baker ]
April 25, 200223 yr You can also use the Case function, so you don't have to say If every time. It could end up being just as long, though Ken
April 25, 200223 yr Just so people know how. A case is so much cleaner than a multi line IF. And a hell of a lot easier to read when used in a calculation field. Case ( Name = "Fred", "Hi Fred", Name = "Bill", "Hi Bill", Name = "Karen", "Hi Karen", Name = "Sam", "Hi Sam", Name = "Mike", "Hi Mike", Name = "Sue", "Hi Sue", "Never heard of you" ) The last line is if none of the above match then use this
April 25, 200223 yr Ken, thanks. Always around if you need help with a project. If you get stuck drop me a line.
April 25, 200223 yr You can also split a script up if you have many multiple If/Else steps. One way to keep it clean and eliminate some confusion. Also helps to put in multiple pauses initially to make sure that each step occurs correctly.
April 25, 200223 yr True, or instead of pauses get filemaker developer 5.5 and never wonder if you left a pause in somewhere. A frustration when your users get stuck in a pause and cant think why.
April 29, 200223 yr Two clarifications: 1. If ( ) requires a default result; with Case ( ) it's optional. 1b. You can't use Case ( ) in a script anyway. 2. Sometimes you don't need Else, you can just use multiple If's without nesting. Only works where the If's are mutually exclusive, or you want more than one to be evaluated, so... doesn't always apply, but where it does, it's less confusing to read. E.g. If (Month(Status(CurrentDate)) = 1) . Perform Script (January) End If If (Month(Status(CurrentDate)) = 2) . Perform Script (February) End If etc.
April 30, 200223 yr However, you can simulate Case in the script using multiple if's without nesting, and puting ExitScript after every statement (simulating "break") Using Fitch's example: If (Month(Status(CurrentDate)) = 1) . Perform Script (January) Exit Script End If If (Month(Status(CurrentDate)) = 2) . Perform Script (February) Exit Script End If etc Dj
May 3, 200223 yr Hello again. Tfitch, youre absolutely right. Except one thing: you can most certainly use a Case function in a script. I use them all the time when inserting calculated results in scripts. They can also be used in IF functions, but doing so seems redundant. I mentioned the case function as an alternative to scripting multiple IF functions. Ken
Create an account or sign in to comment