This is a public Forum  publicRSS

Forum post

    dg3321
    If StatementsAnswered
    Forum post posted June 22, 2010 by dg3321, last edited February 9, 2012 
    773 Views, 2 Comments
    Title:
    If Statements
    Post:

    I'm relatively new at FMP 11 and have a question about if statements.  When writing an if statement into a script, does 'else' mean 'or'?

     

    How do i write an if statement basically saying if Field A = blue (on the current layout), when clicking Button A, go to Blue Page or if Field A = green, when clicking button A, go to the green page etc, etc...

    Best Answer

    Steve Wright

    No, Else does not mean OR..  (see second example for using OR)

     

    in your case, the script steps could look like : 

     

     

    If [ Field A = "blue"]
    
      Go to layout ["blue-page"]
    
    Else If [ Field A = "red"]
    
      Go to layout ["red-page"]
    
    End If
    

     

    basically, if the field contains blue, then go to the blue page, otherwise check if the field contains red.. etc

     

    Using OR you would do something like : 

     

     

    If [ Field A = "blue" OR Field A = "red"]
    
      Go to layout ["red-or-blue-page"]
    
    Else If [ Field A = "green"]
    
      Go to layout ["green-page"]
    
    Else
    
      Go to layout ["basic-page"]
    
    End If
    

     

    if the field contains blue or red, then go to the red-blue page, otherwise check if the field contains green, if it does contain green go to the green page, otherwise none of your criteria was matched, so just go to the basic page.

    Answer

     

    • Steve Wright

      No, Else does not mean OR..  (see second example for using OR)

       

      in your case, the script steps could look like : 

       

       

      If [ Field A = "blue"]
      
        Go to layout ["blue-page"]
      
      Else If [ Field A = "red"]
      
        Go to layout ["red-page"]
      
      End If
      

       

      basically, if the field contains blue, then go to the blue page, otherwise check if the field contains red.. etc

       

      Using OR you would do something like : 

       

       

      If [ Field A = "blue" OR Field A = "red"]
      
        Go to layout ["red-or-blue-page"]
      
      Else If [ Field A = "green"]
      
        Go to layout ["green-page"]
      
      Else
      
        Go to layout ["basic-page"]
      
      End If
      

       

      if the field contains blue or red, then go to the red-blue page, otherwise check if the field contains green, if it does contain green go to the green page, otherwise none of your criteria was matched, so just go to the basic page.

    • PhilModJunk

      If your field stored the name or number of the desired layout, you wouldn't even need an IF statement.

       

      You could then use Go To Layout [Table::Field] after selecting either Layout name by calculation or layout number by calculation.

       

      That reduces this entire script to a single line.