dcsimg
Results 1 to 5 of 5
  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2010
    Posts
    1,096

    Resolved [RESOLVED] 'Division By Zero' Error

    VB Report 'Run-Time error 11' ('Division By Zero' Error) in VB6/SP6/XP SP3. What is the reason?

    Code:
    Dim yOff As Double, dblVPos As Double, dblZoom As Double
    
    dblVPos = 101.196264584032
    dblZoom = 0.486455791667741
    yOff = -(dblVPos  Mod dblZoom)

  2. #2
    Frenzied Member Lightning's Avatar
    Join Date
    Oct 2002
    Location
    Eygelshoven
    Posts
    1,611

    Re: 'Division By Zero' Error

    Mod, in vb6 works with integers not with double. so .48nnn is converted to 0
    VB6 & C# (WCF LINQ) mostly


    If you need help with a WPF/WCF question post in the NEW WPF & WCF forum and we will try help the best we can

    My site

    My blog, couding troubles and solutions

    Free online tools

  3. #3
    Super Moderator Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    Re: 'Division By Zero' Error

    If the number to the left of the decimal is 0, and in this case it is, you will always get that error regardless of how the variables are declared.

    You can not divide buy 0...that is the reason for the error. The error will ALWAYS happen when attempting to divide by 0. The only way to fix it is to not attempt to divide by 0
    Please use [Code]your code goes in here[/Code] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.

    Creating A Wizard In VB.NET
    Paging A Recordset
    What is wrong with using On Error Resume Next
    Good Article: Language Enhancements In Visual Basic 2010
    Upgrading VB6 Code To VB.NET
    Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked

  4. #4
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: 'Division By Zero' Error

    Quote Originally Posted by Hack View Post
    If the number to the left of the decimal is 0, and in this case it is, you will always get that error regardless of how the variables are declared.
    If Abs(dblZoom) <= 0.5 then "Division by 0" Else "It's OK"

    Mod is an operator for integers only (Long, Integer, Byte).
    If use with other data type numbers they will be implicitly converted to Long (with banking rounding effect) before calculation.
    Code:
    12.6 Mod 5.49 = 13 Mod 5 = 3
    12.6 Mod 5.51 = 13 Mod 6 = 1
    12.4 Mod 0.51 = 12 Mod 1 = 0
    12.4 Mod 0.49 = 12 Mod 0 : Division By Zero
    (10^9) Mod 7.49 = 1000000000 Mod 7 = 3
    (10^10) Mod 7.49 = 10000000000 Mod 7 : Overflow
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    Baby Steps a guided tour
    IsDigits() and IsNumber() functions Wichmann-Hill Random() function >> and << functions for VB CopyFileByChunk

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2010
    Posts
    1,096

    Re: 'Division By Zero' Error

    Quote Originally Posted by anhn View Post
    If Abs(dblZoom) <= 0.5 then "Division by 0" Else "It's OK"

    Mod is an operator for integers only (Long, Integer, Byte).
    If use with other data type numbers they will be implicitly converted to Long (with banking rounding effect) before calculation.
    Code:
    12.6 Mod 5.49 = 13 Mod 5 = 3
    12.6 Mod 5.51 = 13 Mod 6 = 1
    12.4 Mod 0.51 = 12 Mod 1 = 0
    12.4 Mod 0.49 = 12 Mod 0 : Division By Zero
    (10^9) Mod 7.49 = 1000000000 Mod 7 = 3
    (10^10) Mod 7.49 = 10000000000 Mod 7 : Overflow
    OK. Thank all of you.
    I try a substitute of Mod,it works for Double.
    Link : http://www.xtremevbtalk.com/showthread.php?t=296072
    By Rockoon Rockoon
    Code:
    Private Function Remainder(numerator As Double, denominator As Double) As Double
      ' Return the remainder of Numerator / Denominator
      Dim x As Double
      
      x = (numerator / denominator)
      x = x - Int(x)
      
      Remainder = x * denominator
      
    End Function

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width


×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.