Page Index Toggle Pages: 1 [2] 3  Send Topic Send Topic Print Print
Very Hot Topic (More than 25 Replies) Running Total for subform lines (Read 4374 times)
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Running Total for subform lines
Reply #15 - Mar 5th, 2007 at 10:49pm
Print Post Print Post  
Let's make sure your code is running and get an idea of what it's doing. We'll do this by interspersing some WriteLn calls that will pop up a little window with some information. Here is your code with the WriteLns in it.

SubRoutine CalculateParts() 

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

WriteLn("STARTING CALC")

vRecord = 1 //Record variable 

vCount = @FormResultSetTotal("Repair1") 

WriteLn("GOT " + @Str(vCount) + " RECORDS")
If vCount > 0 Then 

While vRecord <= vCount 

//Loop through subrecords adding up totals. 
vTotal = vTotal + @TM(@FormFieldValue("Repair1", "Parts", vRecord)) 
WriteLn("vTotal: " + @Str(vTotal))
vRecord = vRecord + 1 


//Place values in elements on form 
TotalRepairs = vTotal 

WriteLn("DONE CALC")
End SubRoutine


Run this on a record.

If you don't ever see "STARTING CALC" then you are never running the Subroutine. Make sure you are actually calling it someplace.

If GOT # RECORDS always says 0, your form name is wrong.

If vTotal is always 0, you don't have an element called Parts in the subform.

Let us know what happens.
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
charliebrown
Junior Member
Members
**
Offline


Beware...novice at large

Posts: 97
Location: Sacramento, CA
Joined: Apr 19th, 2006
Re: Running Total for subform lines
Reply #16 - Mar 5th, 2007 at 11:17pm
Print Post Print Post  
Smiley Thanks boss...I'm such a rookie... Roll Eyes

I'll run this as soon as I get home.  It's a little less hectic there and I'm less likely to type lines in the code such as, "vRecord = 1 // no i haven't had lunch yet @FormResultSetTotal i need to finsh this leave me alone and put the phones on send for the rest of the week End Subroutine..."

I'll post the result...sincere thanks!



  
Back to top
 
IP Logged
 
charliebrown
Junior Member
Members
**
Offline


Beware...novice at large

Posts: 97
Location: Sacramento, CA
Joined: Apr 19th, 2006
Re: Running Total for subform lines
Reply #17 - Mar 6th, 2007 at 4:43pm
Print Post Print Post  
Hammer wrote on Mar 5th, 2007 at 10:49pm:
Let's make sure your code is running and get an idea of what it's doing. We'll do this by interspersing some WriteLn calls that will pop up a little window with some information. Here is your code with the WriteLns in it.

SubRoutine CalculateParts()  

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

WriteLn("STARTING CALC")

vRecord = 1 //Record variable  

vCount = @FormResultSetTotal("Repair1")  

WriteLn("GOT " + @Str(vCount) + " RECORDS")
If vCount > 0 Then  
{  
While vRecord <= vCount  
{  
//Loop through subrecords adding up totals.  
vTotal = vTotal + @TM(@FormFieldValue("Repair1", "Parts", vRecord))  
WriteLn("vTotal: " + @Str(vTotal))
vRecord = vRecord + 1  
}  

//Place values in elements on form  
TotalRepairs = vTotal  
}  
WriteLn("DONE CALC")
End SubRoutine


Run this on a record.

If you don't ever see "STARTING CALC" then you are never running the Subroutine. Make sure you are actually calling it someplace.

If GOT # RECORDS always says 0, your form name is wrong.

If vTotal is always 0, you don't have an element called Parts in the subform.

Let us know what happens.


Good morning:)

Here is a link to various screenshots of my databases (Inventory and Repair) and screenshots of the Program Editor window (Code tests without errors, btw)...

http://pg.photos.yahoo.com/ph/cspedden/album?.dir=/e5c3scd&.src=ph

I've run in preview mode, saved it, reconciled it, run multiple search/update, run in add data mode...I'm not getting a WriteLn window popping up or any data in my TotalRepairs field.   Huh  I'm obviously missing something that's preventing code from running properly, even though it's error free when I test it.

An double shot of espresso is in order me thinks... Undecided
  
Back to top
 
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Running Total for subform lines
Reply #18 - Mar 6th, 2007 at 5:32pm
Print Post Print Post  
I suspect you are not actually calling the Subroutine at all.  You can write a subroutine, but it does not actually run until you tell it to. Try this:

1. If your subroutine is not in the GLOBAL CODE area of your Mass Update, put it there.

2. In the Mass Update event for any other element in your Mass Update, type:
Code
Select All
CalculateParts() 



See how that does.
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
CapitalG
Full Member
Members
***
Offline



Posts: 143
Location: Phoenix, Arizona
Joined: Mar 4th, 2003
Re: Running Total for subform lines
Reply #19 - Mar 8th, 2007 at 8:36pm
Print Post Print Post  
I am finally getting to work with the original code posted by Bob Hansen.  When I test the code, I get the following error:

Error while parsing module "  GLOBAL CODE :srCalculateTotalCost":
Symbol expected [}], symbol found [Identifier].
Line 29, position 17: [Identifier:RunningTotal]
  RunningTotal =  vRunningTotal
                       ^

Any suggestions?

Thanks
  
Back to top
 
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Running Total for subform lines
Reply #20 - Mar 8th, 2007 at 8:46pm
Print Post Print Post  
It looks like you lost a curly brace someplace. It says it was looking for } and found RunningTotal instead. Look for missing curly brace, parentheses, quote marks... Stuff like that.
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
CapitalG
Full Member
Members
***
Offline



Posts: 143
Location: Phoenix, Arizona
Joined: Mar 4th, 2003
Re: Running Total for subform lines
Reply #21 - Mar 8th, 2007 at 8:50pm
Print Post Print Post  
Thanks.

That's what I thought it was telling me.  However, I am not very good with programming.  I could not see a missing curly brace.  Here is my code :

SubRoutine srCalculateTotalCost()

/*
Purpose is to calculate a Total for parent form and RunningTotal for subform
Structure is Parent Form name is frmParent, subform with natural link is named sfrmChild.
Currency element on frmParent, named TotalCost to show total of Cost for all lines in subform.
Currenty element on sfrmChild named Cost to show Cost for that individual record.
Unbound element on sfrmChild, named RunningTotal, ReadOnly, to show running total for Costs for all records in the subform.
Defined as subroutine so can be called on sfrmCost-OnExitElement and on sfrmCost-OnFormExit, 
Is also defined and called on frmParent-OnFormEntry.
*/
//==============================================

var vCount As Int            //Count number of records in subForm
var vLoop As Int            //While loop counter
var vTotal As Double            //Total Cost for all records in subForm
var vRunningTotal As Double      //Running total of Cost

If @FormIsStandalone() = 0 Then {

     vTotal = 0
     vRunningTotal = 0
     vCount = @FormResultSetTotal("sfrmChild")
     
     vLoop = 1
     While vLoop <= vCount {
           vTotal +=    @ToNumber(@FormFieldValue("sfrmChild","Cost",vLoop))
           vRunningTotal = vTotal
           RunningTotal = vRunningTotal
           vLoop += 1
           }

     If vTotal > 0 Then {
           FormFieldValue("frmParent","TotalCost",0,vTotal)
           }
     }

End SubRoutine
//======================================


  
Back to top
 
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Running Total for subform lines
Reply #22 - Mar 8th, 2007 at 9:17pm
Print Post Print Post  
Do you have an element on your form called RunningTotal? If not, you will get this error.
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: Running Total for subform lines
Reply #23 - Mar 8th, 2007 at 9:30pm
Print Post Print Post  
Hold on.....

I just pasted my code from the forum into a test database and I am getting the same error.  Let me find out what is wrong.

Again, the code I submitted was an edited version of a working application, I must have missed something.  As Erika points out, it would seem to a missing or extra } or similar item.    Stay tuned......

Edited......
RunningTotal is an element on sfrmChild, it does not exist on frmParent.

So this needs to be modified, by adding an invisible RunningTotal element to frmParent, or making the line in code a conditional line..........    Stay tuned......

Edited again.....
GOT IT !
As noted above the code is referencing a missing element.  At one time I was calling the function from both frmParent and frmChild.  I forgot to remove the call from frmParent in my instructions.

THE FIX:
Do not call this function from frmParent.  Only call from elements on sfrmChild.


I have also modified my original posting to include that element in the set up instructions.

Thanks CapitalG for pointing out the problem.
Sorry about any confusion.   Embarrassed


« Last Edit: Mar 8th, 2007 at 10:31pm by Bob_Hansen »  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
CapitalG
Full Member
Members
***
Offline



Posts: 143
Location: Phoenix, Arizona
Joined: Mar 4th, 2003
Re: Running Total for subform lines
Reply #24 - Mar 9th, 2007 at 3:05pm
Print Post Print Post  
Grin Grin   Thanks!    Grin Grin
  
Back to top
 
IP Logged
 
charliebrown
Junior Member
Members
**
Offline


Beware...novice at large

Posts: 97
Location: Sacramento, CA
Joined: Apr 19th, 2006
Re: Running Total for subform lines
Reply #25 - Mar 12th, 2007 at 4:06pm
Print Post Print Post  
Bob_Hansen wrote on Mar 8th, 2007 at 9:30pm:
Hold on.....



Thanks CapitalG for pointing out the problem.
Sorry about any confusion.   Embarrassed



No need to apologize to me Bob...it's refreshing to have someone confusing me other than myself  Roll Eyes
  
Back to top
 
IP Logged
 
charliebrown
Junior Member
Members
**
Offline


Beware...novice at large

Posts: 97
Location: Sacramento, CA
Joined: Apr 19th, 2006
Re: Running Total for subform lines
Reply #26 - Mar 14th, 2007 at 5:33pm
Print Post Print Post  
Hammer wrote on Mar 6th, 2007 at 5:32pm:
I suspect you are not actually calling the Subroutine at all.  You can write a subroutine, but it does not actually run until you tell it to. Try this:

1. If your subroutine is not in the GLOBAL CODE area of your Mass Update, put it there.

2. In the Mass Update event for any other element in your Mass Update, type:
Code
Select All
CalculateParts() 



See how that does.


Thank you!!!  That was it Erika.   Runs great-all data seems to be intact...still testing a bit.  One question:

I've tried to have the value in the TotalParts field show as "money" with 2 decimal points, "$" sign...getting errors when I test the code.  I tried going back and creating a new LE bound to money on a copy of the design form...doesn't run. 

This is the line I was trying to add to my above code:

TotalRepairs \#$#,#0.00

Is there something I'm missing?
  
Back to top
 
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Running Total for subform lines
Reply #27 - Mar 14th, 2007 at 5:52pm
Print Post Print Post  
charliebrown wrote on Mar 14th, 2007 at 5:33pm:
This is the line I was trying to add to my above code:

TotalRepairs \#$#,#0.00

Is there something I'm missing?


The line you show above will do something if you enter it as a switch in a mergefield in a Microsoft Word document. Sesame, however, considers it to be gobbledygook! (That's the technical term.)

Get rid of that line and just format your element as Money with 2 decimal places.
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
charliebrown
Junior Member
Members
**
Offline


Beware...novice at large

Posts: 97
Location: Sacramento, CA
Joined: Apr 19th, 2006
Re: Running Total for subform lines
Reply #28 - Mar 14th, 2007 at 7:16pm
Print Post Print Post  
Hammer wrote on Mar 14th, 2007 at 5:52pm:
charliebrown wrote on Mar 14th, 2007 at 5:33pm:
This is the line I was trying to add to my above code:

TotalRepairs \#$#,#0.00

Is there something I'm missing?


The line you show above will do something if you enter it as a switch in a mergefield in a Microsoft Word document. Sesame, however, considers it to be gobbledygook! (That's the technical term.)

Get rid of that line and just format your element as Money with 2 decimal places.


Gobbledygook is nothing I want that in my programming  Shocked  Thank you Erika...again... Embarrassed
  
Back to top
 
IP Logged
 
charliebrown
Junior Member
Members
**
Offline


Beware...novice at large

Posts: 97
Location: Sacramento, CA
Joined: Apr 19th, 2006
Re: Running Total for subform lines
Reply #29 - Mar 14th, 2007 at 8:59pm
Print Post Print Post  
Hammer wrote on Mar 14th, 2007 at 5:52pm:
charliebrown wrote on Mar 14th, 2007 at 5:33pm:
This is the line I was trying to add to my above code:

TotalRepairs \#$#,#0.00

Is there something I'm missing?


The line you show above will do something if you enter it as a switch in a mergefield in a Microsoft Word document. Sesame, however, considers it to be gobbledygook! (That's the technical term.)

Get rid of that line and just format your element as Money with 2 decimal places.



As ordered...garbage in, garbage out  Sad

And of course, when everything is as it should be...wonderous things happen  Grin  Thank you Erika, Bob and everyone...  SmileyRoll Eyes

http://us.a2.yahoofs.com/users/456dd110z2ef31adb/e5c3scd/__sr_/df5bscd.jpgphQJG....

http://pg.photos.yahoo.com/ph/cspedden/detail?.dir=e5c3scd&.dnm=df5bscd.jpg&.src...
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1 [2] 3 
Send Topic Send Topic Print Print