nightdesigns Posted April 21, 2002 Posted April 21, 2002 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
RussBaker Posted April 21, 2002 Posted April 21, 2002 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 ]
nightdesigns Posted April 21, 2002 Author Posted April 21, 2002 Thanks. That works. Just wish there was a cleaner way. Get's confusing when you're 5, 6, 7, levels deep. -j
RussBaker Posted April 22, 2002 Posted April 22, 2002 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 ]
kenneth2k1 Posted April 25, 2002 Posted April 25, 2002 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
andygaunt Posted April 25, 2002 Posted April 25, 2002 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
kenneth2k1 Posted April 25, 2002 Posted April 25, 2002 Nice explanation, andy. I wish I had you around when I was learning it! Ken
andygaunt Posted April 25, 2002 Posted April 25, 2002 Ken, thanks. Always around if you need help with a project. If you get stuck drop me a line.
agraham999 Posted April 25, 2002 Posted April 25, 2002 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.
andygaunt Posted April 25, 2002 Posted April 25, 2002 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.
Fitch Posted April 29, 2002 Posted April 29, 2002 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.
djgogi Posted April 30, 2002 Posted April 30, 2002 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
kenneth2k1 Posted May 3, 2002 Posted May 3, 2002 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
Recommended Posts
This topic is 8244 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 accountSign in
Already have an account? Sign in here.
Sign In Now