Normal Topic running balance (Read 1290 times)
layers
Member
*
Offline


No personal text

Posts: 31
Joined: Jan 2nd, 2004
running balance
Jan 26th, 2004 at 10:17pm
Print Post Print Post  
Simple question I think. I need to keep a running balance based on result of last record. i.e I have a field called balance that needs to be carried from the last record to the new one. This balance will then chage (add or subtract to it) depending on additions or subtractions based on other fields. The now new balance has to be carried over to the next new record.
Make sense?
  
Back to top
 
IP Logged
 
Bharat_Naik
Senior Member
Members
*****
Offline


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Re: running balance
Reply #1 - Jan 26th, 2004 at 10:35pm
Print Post Print Post  
  
Back to top
 
IP Logged
 
layers
Member
*
Offline


No personal text

Posts: 31
Joined: Jan 2nd, 2004
Re: running balance
Reply #2 - Jan 26th, 2004 at 11:55pm
Print Post Print Post  
Sorry, makes no sense to a non-programmer like me.
Thought I could use a @globalvalue
  
Back to top
 
IP Logged
 
Bharat_Naik
Senior Member
Members
*****
Offline


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Re: running balance
Reply #3 - Jan 27th, 2004 at 2:48am
Print Post Print Post  
Try the one in the following link. I think, it is a lot easier.

http://www.lantica.com/Forum2/cgi-bin/yabb/YaBB.pl?board=gen_disc;action=display...
  
Back to top
 
IP Logged
 
layers
Member
*
Offline


No personal text

Posts: 31
Joined: Jan 2nd, 2004
Re: running balance
Reply #4 - Jan 27th, 2004 at 3:49am
Print Post Print Post  
I appreciate your help but maybe I need to re-explain myself (or I'm presently too dense to comprehend) All I need to do is
grab 1 number from the very last record and carry it to a new record.  So if the last saved record has a field called balance and the value is $1000 I just need that to transfer over to a new record at the add data screen. I could call it old balance
(but this was not my original idea, my original was to just carry it over to the balance field on the form in add data )  and  then perform the math on this amount and store it in the balance field. When this record is saved I now need the new balance to be carried forward to a new record. Thats why I thought I could just make it a @globalvalue but unl;ike a numbering system I do not need it incremented.
Isn't there a simple instruction that can pull a value from the last saved record and put it on a new record?
something on the line of (I'm making this up now)
If oldbalance = "" then oldbalance = getfromlastsavedrecord "balance" or isn't life that simple
  
Back to top
 
IP Logged
 
layers
Member
*
Offline


No personal text

Posts: 31
Joined: Jan 2nd, 2004
Re: running balance
Reply #5 - Jan 27th, 2004 at 4:02am
Print Post Print Post  
Actually now that I think about it ,it would have a major pitfall that if an old record was changed then the "new" value would be out of sequence and not give me the correct value. Or something. Sorry this is a new language and I have yet to mutter "MAMA". 
Instinct tells me a globalvalue would work but have yet to figure out how. I can't imagine that it is that difficult.
It would just be like carrying a balance over on a checkbook.
  
Back to top
 
IP Logged
 
Bharat_Naik
Senior Member
Members
*****
Offline


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Re: running balance
Reply #6 - Jan 27th, 2004 at 4:12am
Print Post Print Post  
GrandTotal = item4 + @xlookupr (@filename, 999999999, "counter", "GrandTotal")


The above formula computes the GrandTotal including the figures on the current record. If you just want to know the Old_Balance

Old_balance = @xlookupr (@filename, 999999999, "counter", "GrandTotal")

(Xlookupr command does not need to have the exact match, it accept next lower value match. The logic is 999999999 being very large number, it will match with the record with the highest value of Counter: element. )

Globalvalue () command can be used for creating a counter.  Counter you will need, whether you will create it using @number or Globalvalue (), it should not matter. With GlobalValue (), you can create multiple counters, while only one @number is used per application.

I hope this should add some clarity.

  
Back to top
 
IP Logged
 
layers
Member
*
Offline


No personal text

Posts: 31
Joined: Jan 2nd, 2004
Re: running balance
Reply #7 - Jan 28th, 2004 at 4:19am
Print Post Print Post  
What I finally got to work was the following:

If old bal = "" then  old bal = @xlr(@filename,control,"tdreport!control","balance")


control was set as
If @add and control = "" then { 
    control = @tonumber(@GlobalValue("cntrl")) + 1 
    GlobalValue("cntrl", control) }

Have balance set at
BALANCE = PURCHASES - (PAYMENTS + CREDITS) + old bal


Sorry you  didn't know that the application had multiple data bases thus the need for tdreport!

See anything that could cause problems later on?
1st statement runs when exiting Old bal
2nd statement executes on entering control. 
I see Sesame does the same thing Q&A did if you actually don't enter data in a form  but the control programming executes, leaving a blank form w/ just a  control number and then sequences to the next number. Does not "seem" to effect the old bal total yet but haven't tested it fully yet.
BTW there was I thread about decreasing the zeros in table view? Can that be done?
  
Back to top
 
IP Logged