I've write the following VB code.
Dim qu1, qu2, facroredload, bx, iterations, q3, err As Double
bx = 0.1
qu1 = "constant"
For iterations = 0 To 10000
qu2 = "constant" * bx
q3 = qu1 + qu2
facroredload = "constant" / bx ^ 2
err = Math.Abs(q3 - facroredload)
Select Case err
Case > 10
bx += 0.1
Case err <= 10 And err > 1
bx = bx + 0.01
Case err <= 1 And err > 0.1
bx = bx + 0.001
Case err <= 0.1 And err > 0.01
bx = bx + 0.0001
Case err < 0.01
Exit For
End Select
Next
bx value reaches 1.700000000004 (I don't know why the code adds too many decimals) and then it never changes. The For statement still exciting but, bx never goes beyond 1.7 even though Case err <= 10 And err > 1 is true.
VB's
Select Caseis really just a fancy if statement. How eachCasegets translated to an if expression depends on the format of the case expression. There are three options:Case 1 to 10. This translates toIf err >= 1 And err <= 10.>that begins your firstCase. When using this syntax, it just inserts your test expression before the case expression, as inIf err > 10.Case. This situation is treated exactly like the case with a comparison operator, where the comparison operator is implied to be=. This means your secondCaseis treated asIf err = (err <= 10 And err > 1).Once you understand this you should be able to see why your second
Casestatement doesn't work for you. Iferris 1.7, then the second case statement boils down toIf err = True, but err is not True, it is a number between 1 and 10.To fix your code you have a couple of options. The simplest solution is this:
If more than one
Caseis satisfied, only the first satisfied clause will be executed, just like anIf/ElseIf. That's why the code above works even though it only specifies the lower bound of each range. If you don't like the implied upper bound, you can add it like this:Case > 1 And err <= 10. Personally I think it's actually clearer to leave off the upper bound of each range.