Results 1 to 2 of 2

Thread: Cannot divide by zero problem...

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2006
    Posts
    137

    Cannot divide by zero problem...

    Hi,

    I have a report that is calculating the sum of a percent column.
    I'm storing the count for different values and calculating a total for
    that group. Then I use the total for that group to calculate the percent
    total.
    I'm using the code below:
    Sum ({@valuect}, {Depname.depdes})/Sum ({@grouptotal}, {Depname.depdes})* 100

    I keep receiving the cannot divide by zero error. I tried adding the
    following code:
    if Sum ({@valuect}, {Depname.depdes})<> 0 then Sum ({@valuect}, {Depname.depdes})/Sum ({@grouptotal}, {Depname.depdes})* 100

    When I add the If statement, I have all zeros for the first and last percentage columns.

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Cannot divide by zero problem...

    It's not Sum ({@valuect}, {Depname.depdes}) that's the problem... it's Sum ({@grouptotal}, {Depname.depdes}) .... you need to check to see if Sum ({@grouptotal}, {Depname.depdes}) is 0, and if it is, return 0, ELSE do the calculation.

    =tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width