[comp.databases] dBase/Clipper

pjr@maccs.dcss.mcmaster.ca (Patrick J. Ryan ) (08/05/89)

In trying to run some dbaseIII+ programs using clipper, I have
encountered a problem with the following example:

The database is a baseball team roster which I am trying to order
by batting average.  Thus I have the statement

INDEX ON (1-H/AB) TO BA

(H and AB are numeric fields standing for hits and at-bats respectively)
dbase III+ happily constructs the index, even when some of the records
have a 0 value for AB.  When the list is printed out using the index,
the ratio H/AB is printed out as ****** but occurs at the bottom of
the list, as if it were 0.

Clipper compiles and links ok but when the program runs, it hits a
division by 0 error.  This happens even when there are no records
having AB = 0.
On the other hand, clipper can "list" the file in its standard
ordering and correctly compute and print out H/AB for each 
record.

Does anyone have an idea of why this occurs and/or how to avoid the
problem?  Thanks. 

timk@xenitec.uucp (Tim Kuehn) (08/08/89)

In article <1989Aug4.172532.10732@maccs.dcss.mcmaster.ca> pjr@maccs.dcss.mcmaster.ca (Patrick J. Ryan ) writes:
>In trying to run some dbaseIII+ programs using clipper, I have
>encountered a problem with the following example:
>
>The database is a baseball team roster which I am trying to order
>by batting average.  Thus I have the statement
>
>INDEX ON (1-H/AB) TO BA
>
>(H and AB are numeric fields standing for hits and at-bats respectively)
>dbase III+ happily constructs the index, even when some of the records
>have a 0 value for AB.  When the list is printed out using the index,
>the ratio H/AB is printed out as ****** but occurs at the bottom of
>the list, as if it were 0.
>
>Clipper compiles and links ok but when the program runs, it hits a
>division by 0 error.  This happens even when there are no records
>having AB = 0.
>
>Does anyone have an idea of why this occurs and/or how to avoid the
>problem?  Thanks. 

dbase III+ allows divide by zero and doesn't complain? Sheesh!

For your clipper index I suggest:

Index on iif(ab=0,0,1-h/ab) to ba

(you can replace the ',0,' with any appropriate number you like).

+-----------------------------------------------------------------------------+
|Timothy D. Kuehn	       			       timk@xenitec	      |
|TDK Consulting Services			       !watmath!xenitec!timk  |
|871 Victoria St. North, Suite 217A					      |
|Kitchener, Ontario, Canada N2B 3S4 		       (519)-741-3623 	      |
|DOS/Xenix - SW/HW. uC, uP, DBMS. 		       Satisfaction Gauranteed|
+-----------------------------------------------------------------------------+