October 8th, 2012, 04:34 AM
Hello to everybody,
I have compile error due to following error, thanks to those who can really help me on this problem.
s3BreakDown = 12
s4BreakDown = 0
s5BreakDown = IIf(s3BreakDown * s4BreakDown = 0, 0, s3BreakDown - s4BreakDown / s4BreakDown) --->this lines will generate overflow problems.
October 8th, 2012, 11:21 AM
What are those variables declared as ?
October 9th, 2012, 02:29 AM
You cannot divide by zero; it will always produce an error.
October 9th, 2012, 03:07 PM
That is true, however, the IIf should use the first, not the second condition.
Originally Posted by couttsj
However, this is not the case. In a beautiful example of flummoxing engineering VB actually evaluates both even though it's completely unnecessary to do so!
Replace the IIf with a traditional If Then Else block instead.
Originally Posted by VBA HELP
Be sure to pay attention to operator precedence and also understand that this is the same as
If (s3breakdown * s4breakdown = 0) Then
s5breakdown = 0
s5breakdown = s3breakdown - s4breakdown / s4breakdown
s5breakdown = s3breakdown - (s4breakdown / s4breakdown)
s5breakdown = (s3breakdown - s4breakdown) / s4breakdown
THIS IS IMPORTANT: as you have written it, this is also the same as:
s5breakdown = s3breakdown - 1
because n / n always equals 1 for all times when n is not 0, and if n is 0 it's mathematically impossible
Comments on this post
Last edited by medialint; October 9th, 2012 at 03:15 PM.
“Today you are You, that is truer than true. There is no one alive who is Youer than You.” - Dr. Seuss
October 12th, 2012, 07:37 AM
I finally cleared about this is a VB bug, thanks to all your mindful help.
November 6th, 2012, 09:26 PM
This isn't a bug. Some languages short circuit (quit an evaluation once a valid condition is found), some don't. It's like calling the lack of a scanf() function in VB a bug.
Originally Posted by koklimabc