5 Replies Latest reply on Jan 14, 2014 11:12 AM by flybynight

    Basic If Statement Question

    elmoore

      I'm new to writing if statements and need help with what I believe are two relatively simple questions. I'm trying to build a database that will track my students' GPAs (and other info) and would like the statement to go like this:

       

      If an "A" is entered in the Grade field, then enter a 4 in the corresponding Grade Number field.

       

      Also, if a box is checked (Asking if the student and parent addresses are the same), then copy data from the Student Address field into the Parent Address field automatically. If not, leave blank.

       

      Thanks for your help!

       

      Eric

        • 1. Re: Basic If Statement Question
          beverly

          Do research on Lookups (define fields) and auto-enter (define fields). These bits of data should be captured in time (like copy-paste without actually using the clip-board).

           

          Set the Grade Number with an auto-enter based on a Case()

               Case ( Grade = "A" ; 4 ;

               Grade = "B" ; 3 ;

                  ....

                  )

           

          Set the student address field(s) to Lookup based on the parent/student relationship. You can type over these if the address is different.

           

          Beverly

          • 2. Re: Basic If Statement Question
            ninja

            Howdy elmoore,

             

            Just a note to point out that the "If" you asked about and the "Case" Beverly replied with are pretty much the same thing.

            "Case" is basically a simple way to handle a 'multi-If' scenario like yours...

             

            FWIW, I like Beverly's idea of the lookup, but I have tended to use a script launched by the check field (made the field a button) that simply SetField's the fields over.

            In most cases, I would rather have the fields blank until I did something, rather than have a default value that might be wrong...this one is preference all the way.

             

            HTH,

            Eric

            • 3. Re: Basic If Statement Question
              elmoore

              Thanks Beverly,

               

              The Case example worked perfectly, but didn't quite understand the lookups portion. Will do more research.

               

              Thanks again,

               

              Eric

              • 4. Re: Basic If Statement Question
                elmoore

                Eric,

                 

                After some more thought, I was able to achieve both using a Case. The second has the result of the Case being if a check box is checked Yes, enter the contents of the student address field into the parent address field ( Address Same = "Yes" ; Student Address ; )

                 

                Thanks again for the suggestions.

                 

                Eric


                • 5. Re: Basic If Statement Question
                  flybynight

                  Just another + to what the previous posters have suggested. When I started, I used If statements, because I didn't know about Case. You can accomplish anything with one or the other, but as Eric stated it is so much easier when you get into multiple conditions. The basic difference in the syntax is that multiple If statements will nest inside each other (and hence, you have to make sure you end with the same number of closing parens as you have gathered along the way), and Case staements will read more like a list.

                   

                  Even if I only have 1 choice to make, I still use Case, as it is easier to expand on, should the need arrise.

                   

                  As for the other suggestions… this is something I'm learning as well. Not a big deal when your solution is smaller, but as it grows… any time you can have fields set with a script or an auto-enter calc, performance will be better than a standard calc field.

                  Personally, if I were doing it for yours, I would use an auto-enter calc for the GPA and a script for the address check box. But there is always more than 1 way to skin a cat!

                   

                  Laters,

                  -Shawn