#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2009
    Posts
    9
    Rep Power
    0

    Overflow problems


    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.
  2. #2
  3. Humble Learner
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2007
    Location
    Bangalore, India
    Posts
    280
    Rep Power
    119
    What are those variables declared as ?
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Posts
    289
    Rep Power
    44
    You cannot divide by zero; it will always produce an error.

    J.A. Coutts
  6. #4
  7. Type Cast Exception
    Devshed Supreme Being (6500+ posts)

    Join Date
    Apr 2004
    Location
    OAKLAND CA | Adam's Point (Fairyland)
    Posts
    14,954
    Rep Power
    8617
    Originally Posted by couttsj
    You cannot divide by zero; it will always produce an error.

    J.A. Coutts
    That is true, however, the IIf should use the first, not the second condition.

    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!

    Originally Posted by VBA HELP
    IIf always evaluates both truepart and falsepart, even though it returns only one of them. Because of this, you should watch for undesirable side effects. For example, if evaluating falsepart results in a division by zero error, an error occurs even if expr is True.
    Replace the IIf with a traditional If Then Else block instead.

    Code:
        If (s3breakdown * s4breakdown = 0) Then
            s5breakdown = 0
        Else
            s5breakdown = s3breakdown - s4breakdown / s4breakdown
        End If
    Be sure to pay attention to operator precedence and also understand that this is the same as

    s5breakdown = s3breakdown - (s4breakdown / s4breakdown)

    and not

    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

    • debasisdas agrees
    Last edited by medialint; October 9th, 2012 at 02:15 PM.
    medialint.com

    “Today you are You, that is truer than true. There is no one alive who is Youer than You.” - Dr. Seuss
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2009
    Posts
    9
    Rep Power
    0
    I finally cleared about this is a VB bug, thanks to all your mindful help.
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    10
    Rep Power
    0
    Originally Posted by koklimabc
    I finally cleared about this is a VB bug, thanks to all your mindful help.
    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.

IMN logo majestic logo threadwatch logo seochat tools logo