Normal Topic Can I Calculate A Total on Subform (Read 1062 times)
The_Assistant
Member
*
Offline


A tigger's a wonderful
thing!

Posts: 5
Location: Chesterfield, MO
Joined: Mar 1st, 2005
Can I Calculate A Total on Subform
Mar 1st, 2005 at 6:07pm
Print Post Print Post  
I am quite new to this Sesame stuff and trying to help develop an application.  I have a form with tab pages.  I want to have one tab page be "additional items" that will appear on an addendum.  I need Item, Payee and Amount fields

I have made the subform (as a table) and attached it to the tab page but I need to total the subform for each file.  Should I have made the subform relational using my file number?  I hate to have them retype file number with each item as there could be 60 additional items.

Any help would be appreciated.  KB Smiley
  
Back to top
 
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2482
Joined: Aug 20th, 2003
Re: Can I Calculate A Total on Subform
Reply #1 - Mar 1st, 2005 at 10:11pm
Print Post Print Post  
Hello KB,

There is an example of this in the sample application SesameSeasons.db. The code can be found on the invoice form in a subroutine called CalculateInv() in global code. If you have any questions about it, feel free to ask.

-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
The_Assistant
Member
*
Offline


A tigger's a wonderful
thing!

Posts: 5
Location: Chesterfield, MO
Joined: Mar 1st, 2005
Re: Can I Calculate A Total on Subform
Reply #2 - Mar 1st, 2005 at 11:29pm
Print Post Print Post  
I looked at SesameSeasons and tried to pare it down to what I needed for my app.  This is what I tried where "Bwr Items" is my subform; "Amount" is the numbers I want to add and "LE25" is the total on my form

SubRoutine CalculateInv()

Var vCount as Int
Var vTotal as Double
Var vRecord as Int


vRecord = 1            //Record variable

vCount = @FormResultSetTotal("Bwr Items")

If vCount > 0 Then
{
     While vRecord <= vCount
     {
           //Loop through subrecords adding up totals.
           vTotal = vTotal + @TM(@FormFieldValue("Bwr Items", "Amount", vRecord))
           vRecord = vRecord + 1
     }

     //Place values in elements on form
     LE25 = vTotal
}
End SubRoutine

I don't get any errors when I check but it doesn't give me a total.  Thanks.
  
Back to top
 
IP Logged
 
Steve_in_Texas
Senior Member
*****
Offline


No personal text

Posts: 893
Location: San Antonio
Joined: Feb 21st, 2004
e: Can I Calculate A Total on Subform
Reply #3 - Mar 2nd, 2005 at 12:29am
Print Post Print Post  
Your program looks fine, just make sure your program is actually "Calling" the subroutine when it is supposed to. Example:

On element entry of a command button:

CalculateInv() //Used to run the subroutine program

Also, you may want to throw in some "writeln's" here and there to get a view of whats happening. Example:

SubRoutine CalculateInv()

Var vCount as Int
Var vTotal as Double
Var vRecord as Int


vRecord = 1  //Record variable

vCount = @FormResultSetTotal("Bwr Items")
writeln("Line Item count = " +vCount)
If vCount > 0 Then
{
While vRecord <= vCount
{
writln("Calculating Item Number "+vRecord)
  //Loop through subrecords adding up totals.
  vTotal = vTotal + @TM(@FormFieldValue("Bwr Items", "Amount", vRecord))
writeln("Total so far is "+vTotal)
  vRecord = vRecord + 1
}

//Place values in elements on form
LE25 = vTotal
}
End SubRoutine


If it still isn't working, then you may have a spelling error when referring to the subform name, LE name, etc. Something simple like that.

Smiley

Steve
  
Back to top
IP Logged
 
The_Assistant
Member
*
Offline


A tigger's a wonderful
thing!

Posts: 5
Location: Chesterfield, MO
Joined: Mar 1st, 2005
Re: Can I Calculate A Total on Subform
Reply #4 - Mar 2nd, 2005 at 3:58am
Print Post Print Post  
Finally got it to work!  Thanks everyone for help.  It is a little messy navigating through the subform in table view though.  You can tab across but have to F10 down.  I find I can arrow down but sometimes the record later disappears.  Whatever!  If we can just teach the users how to navigate the subform it offers great flexibity.

Thanks for your help.  Kathy
  
Back to top
 
IP Logged
 
NICEBERG
Full Member
Members
***
Offline


I came, I saw, I'm still
trying to figure it out!

Posts: 208
Location: Green Bay, WI
Joined: Dec 17th, 2003
Re: Can I Calculate A Total on Subform
Reply #5 - May 23rd, 2005 at 6:57pm
Print Post Print Post  
I had the navigation problem too  ???
Then I added a GoTo programming statement that returned the user to the beginning of the current line of the form. Then they only had to arrow down one time. Grin
  
Back to top
 
IP Logged