+ Reply to Thread
Results 1 to 6 of 6

Thread: Division by zero

  1. #1
    Barn Legend Rebelle will become famous soon enough Rebelle's Avatar
    Join Date
    Mar 2008
    Posts
    1,522
    Rep Power
    5

    Division by zero

    Hi All,

    How should I handle cases where I might have zero...getting the following error:

    Code:
    Microsoft VBScript runtime error '800a000b' 
    Division by zero
    
    field that contains zero:
    Code:
    sActThreeMoAgo1 = rs("ActThreeMoAgo")
    

  2. #2
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Maybe something like?
    Code:
    If sActThreeMoAgo1 = 0 Then
    

  3. #3
    Barn Legend Rebelle will become famous soon enough Rebelle's Avatar
    Join Date
    Mar 2008
    Posts
    1,522
    Rep Power
    5

    Hey RR,

    But is there no way to make the following equal display 0?

    Code:
    0/8
    
    sActThreeMoAgo1/sAnotherFieldName
    

  4. #4
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Quote Originally Posted by Rebelle View Post
    Hey RR,

    But is there no way to make the following equal display 0?

    Code:
    0/8
    
    sActThreeMoAgo1/sAnotherFieldName
    
    I don't think so. Dividing anything by zero will always generate an error. The only way would be to suppress the errors (On Error Resume Next) and then define a variable as zero and make the value the division calculation. I think that would then leave it as zero.

  5. #5
    Lazy Bum micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky's Avatar
    Join Date
    Jul 2008
    Location
    India
    Posts
    1,763
    Blog Entries
    2
    Rep Power
    8

    Ya, if there is division involved, then you must check the value (with which dividing) for zero. If its not 0, only then divide.

    So if its 0 then display 0.

  6. #6
    Barn Legend Rebelle will become famous soon enough Rebelle's Avatar
    Join Date
    Mar 2008
    Posts
    1,522
    Rep Power
    5

    Thanks RR and Micky,

    will try something like you suggested...

    Code:
    if sActThreeMoAgo1 > 0 then
    sMain = sActThreeMoAgo1/sAnotherFieldName
    else
    sMain = "0"
    end if
    

+ Reply to Thread

Bookmarks

Posting Permissions

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

SEO by vBSEO