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

Kenneth Brody kenbrody at bestweb.net
Wed Mar 7 09:28:03 PST 2007


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.


For the same reason, the following code wouldn't work as one might
expect:

loop  If:  xx lt ArraySize
    Then:  MyTotals[xx] = tot(MyAarray[xx]) ; xx = xx + "1" ; goto loop

Here, the is a single total being calculated, and it will contain the
sum of all of the array entries, not just the one that happens to be
currently referenced at subscript xx.

--
KenBrody at BestWeb dot net        spamtrap: <g8ymh8uf001 at sneakemail.com>
http://www.hvcomputer.com
http://www.fileProPlus.com


More information about the Filepro-list mailing list