Normal Topic Division by 0 error (Read 1655 times)
proudpoppy
Full Member
Members
***
Offline


Do What ??

Posts: 420
Location: South Carolina
Joined: Apr 7th, 2004
Division by 0 error
Sep 30th, 2009 at 6:54pm
Print Post Print Post  
I have four fields, pp = purchased price, sv = salvage value, and el = expected life then cv = current value, I have the following programming in the on form entry event and on form change event.

cv = (pp - sv) / el

on form entry is giving no error, but on form change is giving a divison by 0 error.  Undecided
  
Back to top
 
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Division by 0 error
Reply #1 - Sep 30th, 2009 at 7:41pm
Print Post Print Post  
Does el = 0?
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
proudpoppy
Full Member
Members
***
Offline


Do What ??

Posts: 420
Location: South Carolina
Joined: Apr 7th, 2004
Re: Division by 0 error
Reply #2 - Sep 30th, 2009 at 7:42pm
Print Post Print Post  
Changing the code to

If @Update then
{
     cv = (pp - sv) / el
}

seems to have solved the problem.  Huh
  
Back to top
 
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Division by 0 error
Reply #3 - Sep 30th, 2009 at 7:44pm
Print Post Print Post  
If you are in @Add, then you are probably on a new record and el is blank which would equate to 0. What you actually want here is a test for 0 before dividing by an unknown value.

If el <> 0
{
       cv = (pp - sv) / el
}
Else
{
       cv = 0
}
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
proudpoppy
Full Member
Members
***
Offline


Do What ??

Posts: 420
Location: South Carolina
Joined: Apr 7th, 2004
Re: Division by 0 error
Reply #4 - Sep 30th, 2009 at 7:48pm
Print Post Print Post  
Got it.
  
Back to top
 
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Division by 0 error
Reply #5 - Sep 30th, 2009 at 7:49pm
Print Post Print Post  
Actually, in your case, let's make sure to filter blank also.

If @ToNumber(el) <> 0
{
      cv = (pp - sv) / el
}
Else
{
      cv = 0
}
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged