6 Replies Latest reply on Oct 19, 2009 12:08 PM by shuey79

    If statement???

    shuey79

      Title

      If statement???

      Post

      How can I set 2 or more fields/variables based on an if statement: if (field1>=5) field2=.25, variable2=.005 else field2=0, variable2=0 end if.

      I can enter this into the scriptmaker but not in the field calculations scripting. Its of no use to me in the script maker because I don't know how to call that script from the field1's lost focus event (if there is one). I am use to .net and java so filemaker scripting is a bit new to me.

       

      Could someone please help????

       

        • 1. Re: If statement???
          ninja
            

          Howdy shuey79,

           

          Define field2 as a calculation field (Not an autoenter calculation, but a calculation field)

          It's claculation would be

          If ( Field1 >= 5 ; 0.25 ; 0 )

           

          Make variable2 another calculation field (not a variable) like field2 above.

          It's calculation would be

          If ( Field1 >= 5 ; 0.005 ; 0 )

           

          No script needed.

          Consider whether this information should be indexed or unstored (check out the help menus and compare to your needs).

          • 2. Re: If statement???
            shuey79
              

            ok. makes more sense. Its a wierd way to look at this after fooling around in other languages.  Here is exactly what I am trying to get working (I created it in scriptmaker):

             

            If [ Quote::VRT > .05 ]

               If [ Quote::VRT > 20 ]

                   Quote::VRX = 20

               Else

                   Quote::VRX = Quote::VRT

                   Quote::VAD = 1.0057 * Exp ( -.0114 * Quote::VRX)

               End If

            Else If [ Quote::VRT > .01 ]

               Quote::VRX = Quote::VRT

            Else

               Quote::VRX = .01

               Quote::VAD = 1.3226 * Exp ( -.559 * Quote::VRX)

            End If

             

             

            So from what you wrote before I would need to enter the calculation tests in VRX and VAD variables? For instance the first test would be in the variable VRX like this: if (Quote::VRT > .05 & Quote::VRT >20; Quote::VRX = 20) ***I'm not using result2

            Is this right?

            • 3. Re: If statement???
              ninja
                

              Howdy,

               


              shuey79 wrote:

               ***I'm not using result2


               

              I take this to mean that you're not using the Quote::VRT>0.01 test.  Fine by me, your original post didn't mention it anyway.

               


              shuey79 wrote:

               if (Quote::VRT > .05 & Quote::VRT >20; Quote::VRX = 20)

              Is this right?


               

              This is redundant.  Things that are >20 are always >.05 (in my math anyway). 

               

              For Field (not variable) Quote::VRX... 

              If (Quote::VRT >20 ; 20 ; Quote::VRT )

              The syntax follows the logic {If this is true ; set the field to this ; else set it to this}

               

              For Field Quote::VAD...

              If (Quote::VRT > .05 ; 1.0057 * Exp ( -.0114 * Quote::VRX) ; 1.3226 * Exp ( -.559 * Quote::VRX) )

               

              If I made it through the nested if's correctly, this should do the job for you.

              There seems to be a hole in translating from one to the other though...does this cover everything, or is there more to handle for the 0.01 threshold?



              • 4. Re: If statement???
                shuey79
                  

                Oh yea duh.. I should be handling the .01 value. 

                • 5. Re: If statement???
                  ninja
                    

                  Okay then, let's switch to the Case function for the VRX field...

                   

                  VRX field:

                   

                  Case ( Quote::VRT > 20 ; 20 ;

                            Quote::VRT > 0.01 ; Quote::VRT ;

                            0.01 )

                   

                   

                   

                  VAD field:

                   

                  If (Quote::VRT > .05 ; 1.0057 * Exp ( -.0114 * Quote::VRX) ; 1.3226 * Exp ( -.559 * Quote::VRX) )

                   

                   

                  That should cover you.  Now the only open question is what you meant by "***I'm not using result2" up above...

                  • 6. Re: If statement???
                    shuey79
                      

                    When I said that I had over looked the fact that I need the result2 from the if statement-- if(test; result1; result2)

                     

                    Thanks!