Alpha Video Training
Results 1 to 3 of 3

Thread: Recalculate total of 52 fields on a form

  1. #1
    "Certified" Alphaholic MoGrace's Avatar
    Real Name
    Robin
    Join Date
    Mar 2006
    Location
    Los Angeles
    Posts
    3,699

    Default Recalculate total of 52 fields on a form

    This is probably not exactly code archive material, but it took me hours to figure it out without finding any examples in here.

    I used a naming convention on this form for my numeric fields so income amounts start with i_, deductions with d_ and expenses with e_.
    I use this 1 record to create a template table with a fixed number of records for each of the fields on this form. That table is easy to total, but this one was not if changes were made here after posting the template.

    NetInc.png

    Code:
    dim tbl as p
    dim vList as c
    dim iList as c
    dim eList as c
    dim dList as c
    dim totded as n = 0
    dim totexp as n = 0
    dim totinc as n = 0
    dim vTotal as n = 0
    
    topparent.allow_change(.t.)
    tbl = table.current()
    vlist = a5_get_fieldnames(tbl.name_get())
    
    dList = *for_each(foo,foo.value,vlist,left(foo.value,2)="d_")
    'remove the 2 char fields that use this naming convention
    dlist = word_remove(dlist,2)
    dlist = word_remove(dlist,3)
    
    eList = *for_each(foo,foo.value,vlist,left(foo.value,2)="e_")
    iList = *for_each(foo,foo.value,vlist,left(foo.value,2)="i_")
    
    for each fld in iList
        totinc = totinc+eval("tbl."+fld.value)
    next
    
    for each fld in dList
        totded = totded+eval("tbl."+fld.value)
    next
    
    for each fld in eList
        totexp = totexp+eval("tbl."+fld.value)
    next
    
    TOTAL_INC.value = totinc
    TOTAL_DED.value = totded
    TOTAL_AGI.value = totinc - totded
    TOTAL_EXP.value = totexp
    vTotal = totinc - (totded+totexp)
    net_inc.value = vTotal
    updated.value = date()
    topparent.commit()
    Hope someone finds this useful!
    Last edited by MoGrace; 10-12-2018 at 09:47 PM.
    Robin

    Discernment is not needed in things that differ, but in those things that appear to be the same. - Miles Sanford

  2. #2
    "Certified" Alphaholic Ronald Anusiewicz's Avatar
    Real Name
    Ronald Anusiewicz
    Join Date
    Oct 2000
    Location
    Southampton, MA
    Posts
    1,583

    Default Re: Recalculate total of 52 fields on a form

    Robin,

    What a beautiful, clean, easy to read form. Outstanding!! Love it!!

    Oh, and I think the way you are working with the data is brilliant!

    Thanks so much for sharing.
    Alpha Anywhere v3.5
    Version 12.3, Build 2999
    MySql56 & DBF's

    Alpha 4, 5, Anywhere

    Ron Anusiewicz

  3. #3
    "Certified" Alphaholic MoGrace's Avatar
    Real Name
    Robin
    Join Date
    Mar 2006
    Location
    Los Angeles
    Posts
    3,699

    Default Re: Recalculate total of 52 fields on a form

    Thanks Ron, you may have noticed the footprint of a few others I have gleaned from here else I never would have figured it out.
    Robin

    Discernment is not needed in things that differ, but in those things that appear to be the same. - Miles Sanford

Similar Threads

  1. Update Recalculate Fields
    By markbwillard in forum Alpha Five Version 11 - Desktop Applications
    Replies: 1
    Last Post: 01-24-2013, 03:11 PM
  2. RE: Issue: Recalculate Calc Fields (Field Rules)
    By markbwillard in forum Alpha Five Version 11 - Desktop Applications
    Replies: 2
    Last Post: 01-14-2013, 11:48 AM
  3. How to recalculate calculated fields of one record within a grid?
    By René Stout in forum Application Server Version 8
    Replies: 0
    Last Post: 12-29-2007, 01:29 PM
  4. Forcing calc fields to recalculate
    By drgarytraub in forum Alpha Five Version 5
    Replies: 10
    Last Post: 09-23-2003, 04:19 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •