
Jul 8th, 2010, 04:38 AM
#1
Thread Starter
Frenzied Member
[RESOLVED] 'Division By Zero' Error
VB Report 'RunTime 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)

Jul 8th, 2010, 04:46 AM
#2
Re: 'Division By Zero' Error
Mod, in vb6 works with integers not with double. so .48nnn is converted to 0

Jul 8th, 2010, 06:07 AM
#3
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

Jul 8th, 2010, 06:58 AM
#4
Re: 'Division By Zero' Error
Originally Posted by Hack
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

Jul 8th, 2010, 07:22 AM
#5
Thread Starter
Frenzied Member
Re: 'Division By Zero' Error
Originally Posted by anhn
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

Forum Rules

Click Here to Expand Forum to Full Width
