Multiple TOT()s, one field (was RE: TOT(0 seems broke)

Brian K. White brian at aljex.com
Wed Mar 7 11:03:24 PST 2007


----- Original Message ----- 
From: "George Simon" <GSimon at americanriverintl.com>
To: "Kenneth Brody" <kenbrody at bestweb.net>; "Bruce Easton" <bruce at stn.com>
Cc: <filepro-list at lists.celestial.com>
Sent: Wednesday, March 07, 2007 1:17 PM
Subject: RE: Multiple TOT()s, one field (was RE: TOT(0 seems broke)


>
> -----Original Message-----
> From: filepro-list-bounces+george=worldest.com at lists.celestial.com
> [mailto:filepro-list-bounces+george=worldest.com at lists.celestial.com] On
> Behalf Of Kenneth Brody
> Sent: Wednesday, March 07, 2007 12:28 PM
> To: Bruce Easton
> Cc: filepro-list at lists.celestial.com
> Subject: Multiple TOT()s, one field (was RE: TOT(0 seems broke)
>
> Quoting Bruce Easton (Wed, 7 Mar 2007 12:09:16 -0500):
>
>> Kenneth Brody wrote Wednesday, March 07, 2007 10:40 AM:
>> > > Also, here's something you can do with TOT() that will delight and
>> > > confuse everyone here.   :-)
>> > >
>> > >       If:  foobar eq "Y"
>> > >     Then:  xx = tot(foo)
>> > >       If:  foobar ne "Y"
>> > >     Then:  xx = tot(bar)
>> > >
>> > > What would you expect "xx" to hold?  I'll tell you right away that
>> > > it is _not_ the same as
>> > >
>> > >       If:  foobar eq "Y"
>> > >     Then:  xx = xx + foo
>> > >       If:  foobar ne "Y"
>> > >     Then:  xx = xx + bar
> [...]
>> I would expect xx in the first example to hold only the total of foo
>> at that point, if the last occurrence of foobar was "Y", otherwise it
>> would only be the total of bar at that point.
>>
>> In the second, I would expect xx to be the total of all of occurrences
>> that foo and bar held at that point.
>
> Correct to you and Chad.
>
> There are two distinct totals being calculated in example 1.  There
> are the totals for foo when foobar is "Y", and the totals for bar
> when foobar is not "Y", and they are kept track of separately,
> despite both having the current total stored into xx.
>
> In other words, xx contains either tot(foo) or tot(bar), depending
> on the current value of foobar.
>
> --
>
> _______________________________________________
> Filepro-list mailing list
> Filepro-list at lists.celestial.com
> http://mailman.celestial.com/mailman/listinfo/filepro-list
>
> So how is that different from
>       If:  foobar eq "Y"
>     Then:  xx = xx + foo
>       If:  foobar ne "Y"
>     Then:  xx = xx + bar
>
> xx would end up with the same total.  No?
>
> say foo=5 and bar=6
>
> rec# 1 foobar="Y" -- x=0+5 -- x=5
> rec# 2 foobar="N" -- x=5+6 -- x=11
> rec# 3 foobar="N" -- x=11+6 x=17
> rec# 4 foobar="Y" -- x=17+5 x=22
> rec# 5 foobar="Y" -- x=22+5 x=27
>
> What am I missing?

To use variables instead of tot you'd need two different variables, both 
global, aside from and basically unrelated to xx, which doesn't need to be 
global

       If:  foobar eq "Y"
     Then:  f(8,.0,g) = f + foo ; xx = f
       If:  foobar ne "Y"
     Then:  b(8,.0,g) = b + bar ; xx = b


rec# 1 foobar="Y"   f=0+5   xx=5
rec# 2 foobar="N"   b=0+6   xx=6
rec# 3 foobar="N"   b=6+6   xx=12
rec# 4 foobar="Y"   f=5+5   xx=10
rec# 5 foobar="Y"   f=10+5   xx=15

On any given record, xx will equal one or the other of two seperate running 
totals.
On any given record, only one or the other of two seperate running totals is 
updated.

Except I think I don't really have enough to go on to be sure about the 2nd 
statement.

If the tot() always reflects the current total of a given field for all 
records processed so far, then it would look like this instead:

       If:
     Then:  f(8,.0,g) = f + foo ; b(8,.0,g) = b + bar
       If:  foobar eq "Y"
     Then:  xx = f
       If:  foobar ne "Y"
     Then:  xx = b

and assuming foo is always 5 and bar is always 6 on every record...:

rec# 1 foobar="Y"   f=0+5  b=0+6  xx=5
rec# 2 foobar="N"   f=5+5  b=6+6  xx=12
rec# 3 foobar="N"   f=10+5  b=12+6  xx=18
rec# 4 foobar="Y"   f=15+5  b=18+6  xx=20
rec# 5 foobar="Y"   f=20+5  b=24+6  xx=25

I think the first example is the correct one though. I know I know... "what 
happened when I tried it?"
I'm too busy reading emails to code :)

Brian K. White  --  brian at aljex.com  --  http://www.aljex.com/bkw/
+++++[>+++[>+++++>+++++++<<-]<-]>>+.>.+++++.+++++++.-.[>+<---]>++.
filePro  BBx    Linux  SCO  FreeBSD    #callahans  Satriani  Filk!



More information about the Filepro-list mailing list