3 Replies Latest reply on Feb 27, 2014 8:45 AM by philmodjunk

    Multiple Functions?

    RichardStrohman

      Title

      Multiple Functions?

      Post

           Hello everyone.

           I trying to help a friend with a database he is making.  What he has are quantity fields and then an add field for each quantity field.  An example would be "BoltQty1" and  "BoltAdd1".  He has about ten or so of each field with a different number for each. (eg. BoltQty2 and BoltAdd2 ect...)

           Anyway what he does is put the amount of bolts in the BoltQty field and then when he gets more bolts in he put the number in the BoltAdd field and presses a button that adds them together.  The result replaces the existing value in the corresponding BoltQty field.

           He would like to make a script that adds all of the fields separately, for example BoltQty1 = BoltQty1 + BoltAdd1 and so on.  Then he wants the BoltAdd fields to go to zero.

           Is there a way to do this simply or will he have to do a calculated result for each of the ten fields?

        • 1. Re: Multiple Functions?
          philmodjunk
               

                    Is there a way to do this simply

               He could simplify his system greatly by using a related table where each combination of BoltQty and BoltQtyAdd are records in a related table instead of trying to maintain a group of individual fields in the same record. It would also simplify the update that he wants here.

               From the existing fields, he could set up a looping script that uses Set field by name and GetField and a counter variable to update field values and access data from fields without having to specify explicit field names.

          • 2. Re: Multiple Functions?
            RichardStrohman

                 I have suggested that he use related tables, but he already has everything they he wants now and is ready ready to change from that.  What would the option for the existing fields look like?

            • 3. Re: Multiple Functions?
              philmodjunk

                   Yes but you wanted a simpler way to manage it and that simpler way requires a change--which can offer a number of other advantages as well. Consider what has to be done if he finds that he now needs more of these fields. Instead of a simple data entry operation to add another related record, he, or you have to redesign the database to add more fields and update this script.

                   Loop
                      Set Variable [$K ; value: $K + 1]
                      Exit loop if [ $K > specify number of these sets of fields here ]
                      Set Field by Name ["YourTableHere::BoltQty" & $K ; GetField ( "YourTableHere::BoltQTy" & $K ) + GetField ( "YourTableHere::BoltAdd" & $K ) ]
                      Set Field By Name [ "YourTableHere::BoltAdd" & $K ; "" ]
                   End Loop