August 16, 200223 yr Help. What am I doing wrong here? I wrote a script that takes a user to a specific layout based on matching text from a specific field: If field x = "layout 1" goto "layout 1" If field x = "layout 2" goto "layout 2" If field x = "layout 3" goto "layout 3" etc. The problem I'm having is that I want to add a line in the script that takes a user to a "Home Layout" if the contents of this specific field don't match any of the criteria: if field x (is not equal) to "layout 1" or "layout 2# or "layout 3" then goto "layout home" I'm sure this is a syntax problem but I'm just not getting it.
August 16, 200223 yr Assuming you have put the Else's in your scripts and all the End If's, following the last If try Else go to layout home followed by the end if's. This final Else should not require an If.
August 16, 200223 yr This looks like a perfect opportunity to use : GotoLayout (by field) Just go to the layout number given by "X" - no need to have a conditional script at all.
August 16, 200223 yr I suggest that you use a script which intelligently tests whether the layout name is valid by using the PatternCount and LayoutNames functions in combination, uses a loop (in conjuntion with a global number field) to locate the correct layout if the layout name in 'field x' is valid, but sends the user to 'Home Layout' if it is not. The resulting script will look like this: [color:"green"]Set Field ["gScript.num", ""] If ["PatternCount (LayoutNames("yourdbname.fp5"), field x) > 0"] Freeze Window Loop Set Field ["gScript.num", "gScript.num + 1"] Go to Layout ["gScript.num"] Exit Loop If ("Status(CurrentLayoutName) = field x"] End Loop Else Go To Layout ["Home Layout" EndIf This uses the option to Go to Layout "layout number from field..." based on the incremented number in the global field called gScript.num, stopping the loop when the desired layout is reached. The process will take place in a split second. One major advantage of this approach is that you don't have to hard-code layout names (other than 'Home Layout', that is) into the formula. If layout names are changed or new layouts added, the script will still function correctly, based on whatever it finds in 'field x'.
August 16, 200223 yr Author The "Else's" were the problem. I was using "End If" at the end of each line instead of Else. That fixed it right up. Thanks for your help. Carl.
August 16, 200223 yr The timing of this post is perfect. The GotoLayout is exactly what I need for an application I started designing last night. I had forgotten about this script step. Thanks, Mike
August 16, 200223 yr Mark, I was intrigued by your response suggesting, "GotoLayout (by field)" From looking at my copies of FMPro 4.0 and 5.0 I gather that this step is new to FMPro 5.5, or possibly 6.0.
Create an account or sign in to comment