Divide by zero error 
Author Message
 Divide by zero error

Hi all,

I've got a screwy one that I can't understand.  I keep getting an
illegal operation with the exception 10H (Divide by zero error) on this
process below, but I'm testing for zero in the numerator AND the
denominator before doing anything!  It works fine if I substitute 1 for
0 in the 1st query.

The following will break on line 4.  It's always the 2nd time the same
query's run, after the report writer has been activated.  (Even though
nothing's done in it).

select 0 as x, 0 as y from <any table> where .t. into cursor zcc
select x,y, iif(x>0 and y>0, x/y, 1) as z from zcc into cursor zcc2
create report
** as soon as the report writer comes up,
** close it without doing anything
select x,y, iif(x>0 and y>0, x/y, 1) as z from zcc into cursor zcc2

I know I can get around this by doing the calculation in a SCAN loop
after the 1st SQL instead of inside the SQL, but I just don't
understand WHY it's not working in the SQL.

If anyone can explain this to me, I'd be grateful.

Thanks!
Cathy
--
**
Cathy Ciciulla Neppel
Omaha, NE
cneppel *AT* tmvgas.com

Sent via Deja.com http://www.*-*-*.com/
Before you buy.



Sun, 09 Mar 2003 03:00:00 GMT  
 Divide by zero error
In my original post, my line breaks didn't come across right in the
code section, so here's the way it should be ...

select 0 as x, 0 as y from <any table> where .t. into cursor zcc

select x,y, iif(x>0 and y>0, x/y, 1) as z from zcc into cursor zcc2

create report

** as soon as the report writer comes up,

** close it without doing anything

select x,y, iif(x>0 and y>0, x/y, 1) as z from zcc into cursor zcc2

Cathy

Sent via Deja.com http://www.deja.com/
Before you buy.



Sun, 09 Mar 2003 03:00:00 GMT  
 Divide by zero error
I had a similar experience once and using 0.00 instead of 0 made a
difference. Of course, on your machine using your code, it probably
won't work but give it a try. I'd be interested to know.

On Wed, 20 Sep 2000 20:57:06 GMT, Cathy Neppel

Quote:

>In my original post, my line breaks didn't come across right in the
>code section, so here's the way it should be ...

>select 0 as x, 0 as y from <any table> where .t. into cursor zcc

>select x,y, iif(x>0 and y>0, x/y, 1) as z from zcc into cursor zcc2

--
John

(Spam avoidance: Actual address has one S.)


Sun, 09 Mar 2003 03:00:00 GMT  
 Divide by zero error

Your code runs with no problems on my machine. What is in the table you are
initially querying? Try creating a blank table with one c(10) field, no
data, just a bunch of blank records. Query that and see what happens. Are
you running VFP6 SP4? What OS? What cpu? How much memory? Any other odd
problems on this machine?

I've had similar problems before when importing an Excel spreadsheet that
had divide by zero errors in the cells. After the import, the fpu would be
in a divide by zero error state, and VFP would pick up this state and tell
me that there was a divide by zero error in my program. Could there be
something else on your machine that is doing a divide by zero, and VFP is
just picking it up from the fpu without actually being the cause?

I use conditional iif()'s all the time where one of the statements would
cause an error if executed, and I've never ever had it fail me.


Quote:
> Hi all,

> I've got a screwy one that I can't understand.  I keep getting an
> illegal operation with the exception 10H (Divide by zero error) on this
> process below, but I'm testing for zero in the numerator AND the
> denominator before doing anything!  It works fine if I substitute 1 for
> 0 in the 1st query.

> The following will break on line 4.  It's always the 2nd time the same
> query's run, after the report writer has been activated.  (Even though
> nothing's done in it).

> select 0 as x, 0 as y from <any table> where .t. into cursor zcc
> select x,y, iif(x>0 and y>0, x/y, 1) as z from zcc into cursor zcc2
> create report
> ** as soon as the report writer comes up,
> ** close it without doing anything
> select x,y, iif(x>0 and y>0, x/y, 1) as z from zcc into cursor zcc2

> I know I can get around this by doing the calculation in a SCAN loop
> after the 1st SQL instead of inside the SQL, but I just don't
> understand WHY it's not working in the SQL.

> If anyone can explain this to me, I'd be grateful.

> Thanks!
> Cathy
> --
> **
> Cathy Ciciulla Neppel
> Omaha, NE
> cneppel *AT* tmvgas.com

> Sent via Deja.com http://www.deja.com/
> Before you buy.



Sun, 09 Mar 2003 03:00:00 GMT  
 Divide by zero error
Cathy,

You are probably seeing an effect relative to what FoxPro does in
preparation to run the SQL statement. And it's likely that it's evaluating
the x/y outside the context of the IIF(). You might have to run this as two
selects where the first gathers only the rows where y != 0 and then do the
division in the second select.
--
df    - (Microsoft FoxPro MVP) http://www.geocities.com/df_FoxPro/


Quote:
> In my original post, my line breaks didn't come across right in the
> code section, so here's the way it should be ...

> select 0 as x, 0 as y from <any table> where .t. into cursor zcc

> select x,y, iif(x>0 and y>0, x/y, 1) as z from zcc into cursor zcc2

> create report

> ** as soon as the report writer comes up,

> ** close it without doing anything

> select x,y, iif(x>0 and y>0, x/y, 1) as z from zcc into cursor zcc2

> Cathy

> Sent via Deja.com http://www.deja.com/
> Before you buy.



Mon, 10 Mar 2003 03:00:00 GMT  
 Divide by zero error
Interesting.  I'm running VFP 5 still, so I wonder if it's a problem
that went away in 6?  We're sort of suspecting it's actually a printer
driver problem tho, because it's only AFTER I've opened a report (even
a blank one) that we get the error.  I can run the query all day long
without an error as long as I don't open a report.  It's like VFP
handles the divide by zero just fine until some printer variable gets
set in the report writer.  We're using HP printers.  What kind of
printer do you have?

Our environment otherwise is Windows 95 on a Gateway 2000 700 MHz
machine with 128 MB memory.  It's happened on at least 2 different
machines that are less than 6 months old, and no other flaky stuff
seems to be going on.   (So, you see we've gotten complacent!)

Cathy



Quote:

> Your code runs with no problems on my machine. What is in the table
you are
> initially querying? Try creating a blank table with one c(10) field,
no
> data, just a bunch of blank records. Query that and see what happens.
Are
> you running VFP6 SP4? What OS? What cpu? How much memory? Any other
odd
> problems on this machine?

> I've had similar problems before when importing an Excel spreadsheet
that
> had divide by zero errors in the cells. After the import, the fpu
would be
> in a divide by zero error state, and VFP would pick up this state and
tell
> me that there was a divide by zero error in my program. Could there be
> something else on your machine that is doing a divide by zero, and
VFP is
> just picking it up from the fpu without actually being the cause?

> I use conditional iif()'s all the time where one of the statements
would
> cause an error if executed, and I've never ever had it fail me.



> > Hi all,

> > I've got a screwy one that I can't understand.  I keep getting an
> > illegal operation with the exception 10H (Divide by zero error) on
this
> > process below, but I'm testing for zero in the numerator AND the
> > denominator before doing anything!  It works fine if I substitute 1
for
> > 0 in the 1st query.

> > The following will break on line 4.  It's always the 2nd time the
same
> > query's run, after the report writer has been activated.  (Even
though
> > nothing's done in it).

> > select 0 as x, 0 as y from <any table> where .t. into cursor zcc
> > select x,y, iif(x>0 and y>0, x/y, 1) as z from zcc into cursor zcc2
> > create report
> > ** as soon as the report writer comes up,
> > ** close it without doing anything
> > select x,y, iif(x>0 and y>0, x/y, 1) as z from zcc into cursor zcc2

> > I know I can get around this by doing the calculation in a SCAN loop
> > after the 1st SQL instead of inside the SQL, but I just don't
> > understand WHY it's not working in the SQL.

> > If anyone can explain this to me, I'd be grateful.

> > Thanks!
> > Cathy
> > --
> > **
> > Cathy Ciciulla Neppel
> > Omaha, NE
> > cneppel *AT* tmvgas.com

> > Sent via Deja.com http://www.deja.com/
> > Before you buy.

--
**
Cathy Ciciulla Neppel
Omaha, NE
cneppel *AT* tmvgas.com

Sent via Deja.com http://www.deja.com/
Before you buy.



Mon, 10 Mar 2003 03:00:00 GMT  
 Divide by zero error
John,
Thanks for the suggestion.
In the original code there were decimals involved in the variables, and
it was still breaking.  It's strange that it made a difference for you
though.
We're thinking it's actually a printer driver problem possibly, since
the first query will work until the report writer has been opened.
Still a head scratcher tho.

Cathy



Quote:
> I had a similar experience once and using 0.00 instead of 0 made a
> difference. Of course, on your machine using your code, it probably
> won't work but give it a try. I'd be interested to know.

> On Wed, 20 Sep 2000 20:57:06 GMT, Cathy Neppel

> >In my original post, my line breaks didn't come across right in the
> >code section, so here's the way it should be ...

> >select 0 as x, 0 as y from <any table> where .t. into cursor zcc

> >select x,y, iif(x>0 and y>0, x/y, 1) as z from zcc into cursor zcc2

> --
> John

> (Spam avoidance: Actual address has one S.)

--
**
Cathy Ciciulla Neppel
Omaha, NE
cneppel *AT* tmvgas.com

Sent via Deja.com http://www.deja.com/
Before you buy.



Mon, 10 Mar 2003 03:00:00 GMT  
 Divide by zero error

Try this immediately after any query that may perform a divide by zero:

* RESET THE FPU TO CLEAR DIVIDE BY ZERO CONDITION
=_fpreset()

And somewhere in your startup:

  DECLARE _fpreset IN msvcrt40.dll

I have to do this in certain places where an activeX control or some other
process I can't really control does a divide by zero. This clears the fpu so
that VFP doesn't pickup a divide by zero error condition. Also before and/or
after calling the report form may help.


Quote:
> Interesting.  I'm running VFP 5 still, so I wonder if it's a problem
> that went away in 6?  We're sort of suspecting it's actually a printer
> driver problem tho, because it's only AFTER I've opened a report (even
> a blank one) that we get the error.  I can run the query all day long
> without an error as long as I don't open a report.  It's like VFP
> handles the divide by zero just fine until some printer variable gets
> set in the report writer.  We're using HP printers.  What kind of
> printer do you have?

> Our environment otherwise is Windows 95 on a Gateway 2000 700 MHz
> machine with 128 MB memory.  It's happened on at least 2 different
> machines that are less than 6 months old, and no other flaky stuff
> seems to be going on.   (So, you see we've gotten complacent!)

> Cathy



> > Your code runs with no problems on my machine. What is in the table
> you are
> > initially querying? Try creating a blank table with one c(10) field,
> no
> > data, just a bunch of blank records. Query that and see what happens.
> Are
> > you running VFP6 SP4? What OS? What cpu? How much memory? Any other
> odd
> > problems on this machine?

> > I've had similar problems before when importing an Excel spreadsheet
> that
> > had divide by zero errors in the cells. After the import, the fpu
> would be
> > in a divide by zero error state, and VFP would pick up this state and
> tell
> > me that there was a divide by zero error in my program. Could there be
> > something else on your machine that is doing a divide by zero, and
> VFP is
> > just picking it up from the fpu without actually being the cause?

> > I use conditional iif()'s all the time where one of the statements
> would
> > cause an error if executed, and I've never ever had it fail me.



> > > Hi all,

> > > I've got a screwy one that I can't understand.  I keep getting an
> > > illegal operation with the exception 10H (Divide by zero error) on
> this
> > > process below, but I'm testing for zero in the numerator AND the
> > > denominator before doing anything!  It works fine if I substitute 1
> for
> > > 0 in the 1st query.

> > > The following will break on line 4.  It's always the 2nd time the
> same
> > > query's run, after the report writer has been activated.  (Even
> though
> > > nothing's done in it).

> > > select 0 as x, 0 as y from <any table> where .t. into cursor zcc
> > > select x,y, iif(x>0 and y>0, x/y, 1) as z from zcc into cursor zcc2
> > > create report
> > > ** as soon as the report writer comes up,
> > > ** close it without doing anything
> > > select x,y, iif(x>0 and y>0, x/y, 1) as z from zcc into cursor zcc2

> > > I know I can get around this by doing the calculation in a SCAN loop
> > > after the 1st SQL instead of inside the SQL, but I just don't
> > > understand WHY it's not working in the SQL.

> > > If anyone can explain this to me, I'd be grateful.

> > > Thanks!
> > > Cathy
> > > --
> > > **
> > > Cathy Ciciulla Neppel
> > > Omaha, NE
> > > cneppel *AT* tmvgas.com

> > > Sent via Deja.com http://www.deja.com/
> > > Before you buy.

> --
> **
> Cathy Ciciulla Neppel
> Omaha, NE
> cneppel *AT* tmvgas.com

> Sent via Deja.com http://www.deja.com/
> Before you buy.



Mon, 10 Mar 2003 03:00:00 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Divide by zero or overflow error

2. error "overflow or divide by zero"

3. Divide by Zero or Overflow Error

4. Divide by zero error

5. divide by zero error with Foxpro 2.6 and NT4

6. FP2.6W Divide by zero error on fast PC

7. Divide by Zero error can't be fixed

8. 2.6 Divide by Zero Error when loading???

9. FoxPro 2.5 Zero Divide Error on 500Mhz Machine

10. Divide by Zero error

11. Divide by zero error

12. Divide by zero error in 2.6

 

 
Powered by phpBB® Forum Software