Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2016
    Posts
    29
    Provided Answers: 1

    Unanswered: If Statement not working

    Hi guys,

    I have a simple If statement which doesn't appear to be working - it's essentially:

    If a = 0 Then
    b = c
    Else
    b = c * d (d is a calculated small corrective factor)
    End If

    In the line producing the wrong results, a is a small but non-zero value (0.000055), but the If statement is producing b = c regardless. I'm confident that it's not some weird fluke where d = 1, and have tested the hypothesis that a <> 0 is being read as a = 0 in the If statement, by changing the decimal value of c, and changing the Then term to b = c + constant, and it does appear to be computing as if a = 0 (I even tried changing the If statement to "If a * 1000000 = 0 Then, in case it was rounding a to something, but that didn't work either).

    Has anyone had experience with If statements computing incorrectly? Are there any workarounds or other functions I can use to solve this efficiently?

    Many Thanks

  2. #2
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    629
    Provided Answers: 33
    are A,B,C defined as double?

  3. #3
    Join Date
    Nov 2016
    Posts
    29
    Provided Answers: 1
    Yes, all the variables are doubles.

  4. #4
    Join Date
    Nov 2016
    Posts
    29
    Provided Answers: 1
    Worked out the problem, I'd retroactively moved the variable calculating condition a below the If statement and forgotten - missed it in 1600 lines of code. Sorry guys, working til 9pm is not conducive to productive work!

Tags for this Thread

Posting Permissions

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