I have a for loop that seems to be giving me inconsistant
results. It doesn't seem to execute the correct number of
times. Here is my code:
a = Min
CRange = ((Max - Min) * 10) + 1
For x = 1 To CRange
ChD(x, PhaseRange) = a
a = a + 0.1
Next
Min and Max are values that contain up to one decimal place.
Given a certain set of data I had a Min of 0.8 and a Max of 1.
Now the purpose of this loop is to count the difference between Min and
Max in 0.1 increments. So for the values listed I would have 0.8,
0.9, and 1.0. The statement CRange = ((Max - Min) * 10) + 1
should return 3 and it does. I've confirmed this with the
debugger. Now I would expect the For Loop to cycle through 3
times but it doesn't. It only executes twice and then carries
on. I thought maybe it had something to do with Min and Max being
floats so I converted CRange into an integer using Int() but that
didn't help either. What is really boggling me is that for a
different set of data with a different range (0.2-1.8) the Loop
executes the correct number of times (17).
Can anyone shed some light onto this? I'm at my wits end.