From: FM on
Can someone help me turn this ElseIf logic into a For Next loop:

If CTR <= 50 Then
Spinner(1) = True
ElseIf CTR > 50 And CTR <= 100 Then
Spinner(2) = True
ElseIf CTR > 100 And CTR <= 150 Then
Spinner(3) = True
ElseIf CTR > 150 And CTR <= 200 Then
Spinner(4) = True
ElseIf CTR > 200 And CTR <= 250 Then
Spinner(5) = True
ElseIf CTR > 250 And CTR <= 300 Then
Spinner(6) = True
ElseIf CTR > 300 Then
Spinner(7) = True
End If

Regards
FM


From: Rick Rothstein on
I think you will need to tell us more about your set up before you will get
a "good" answer to your question. First off, I'm guessing you request for a
For..Next loop is to have the code iterate the Spinner (control?) array,
correct? Please answer all of the following questions...

1. Do you need the Spinner (control?) array to be set to False if the value
is not in the indicated range?

2. Are those ranges for CTR correct as shown, or are they just made up
example numbers (I ask because regular range intervals like you show lend
themselves to simple mathematical formulas rather than individual range
examinations)?

3. Can CTR ever be less than zero?

4. Can CTR ever be greater than 350?

While you don't seem to want to use your current If..ElseIf..Then format, I
just wanted to point out that you are doing too much testing in the majority
of your If/ElseIf statements. If..ElseIf..Then blocks execute in the order
listed; because of that, once you test for the a less than or equal
condition in the prior test, you don't have to test to see if the number is
greater than that prior test's upper range... it can't be lower or the prior
test would have trapped it. So, your posted code could be simplified to
this...

If CTR <= 50 Then
Spinner(1) = True
ElseIf CTR <= 100 Then
Spinner(2) = True
ElseIf CTR <= 150 Then
Spinner(3) = True
ElseIf CTR <= 200 Then
Spinner(4) = True
ElseIf CTR <= 250 Then
Spinner(5) = True
ElseIf CTR <= 300 Then
Spinner(6) = True
ElseIf 300 Then
Spinner(7) = True
End If

--
Rick (MVP - Excel)



"FM" <spam(a)uce.gov> wrote in message
news:uTwzkDSnKHA.1552(a)TK2MSFTNGP05.phx.gbl...
> Can someone help me turn this ElseIf logic into a For Next loop:
>
> If CTR <= 50 Then
> Spinner(1) = True
> ElseIf CTR > 50 And CTR <= 100 Then
> Spinner(2) = True
> ElseIf CTR > 100 And CTR <= 150 Then
> Spinner(3) = True
> ElseIf CTR > 150 And CTR <= 200 Then
> Spinner(4) = True
> ElseIf CTR > 200 And CTR <= 250 Then
> Spinner(5) = True
> ElseIf CTR > 250 And CTR <= 300 Then
> Spinner(6) = True
> ElseIf CTR > 300 Then
> Spinner(7) = True
> End If
>
> Regards
> FM
>
>

From: Rick Rothstein on
Oh, and what data type (Integer, Long, Single, Double, etc.) is CTR declared
as? If you didn't declare it, then is CTR always a whole number or can it be
a floating point number?

--
Rick (MVP - Excel)


"Rick Rothstein" <rick.newsNO.SPAM(a)NO.SPAMverizon.net> wrote in message
news:e0LR9aSnKHA.1548(a)TK2MSFTNGP04.phx.gbl...
>I think you will need to tell us more about your set up before you will get
>a "good" answer to your question. First off, I'm guessing you request for a
>For..Next loop is to have the code iterate the Spinner (control?) array,
>correct? Please answer all of the following questions...
>
> 1. Do you need the Spinner (control?) array to be set to False if the
> value is not in the indicated range?
>
> 2. Are those ranges for CTR correct as shown, or are they just made up
> example numbers (I ask because regular range intervals like you show lend
> themselves to simple mathematical formulas rather than individual range
> examinations)?
>
> 3. Can CTR ever be less than zero?
>
> 4. Can CTR ever be greater than 350?
>
> While you don't seem to want to use your current If..ElseIf..Then format,
> I just wanted to point out that you are doing too much testing in the
> majority of your If/ElseIf statements. If..ElseIf..Then blocks execute in
> the order listed; because of that, once you test for the a less than or
> equal condition in the prior test, you don't have to test to see if the
> number is greater than that prior test's upper range... it can't be lower
> or the prior test would have trapped it. So, your posted code could be
> simplified to this...
>
> If CTR <= 50 Then
> Spinner(1) = True
> ElseIf CTR <= 100 Then
> Spinner(2) = True
> ElseIf CTR <= 150 Then
> Spinner(3) = True
> ElseIf CTR <= 200 Then
> Spinner(4) = True
> ElseIf CTR <= 250 Then
> Spinner(5) = True
> ElseIf CTR <= 300 Then
> Spinner(6) = True
> ElseIf 300 Then
> Spinner(7) = True
> End If
>
> --
> Rick (MVP - Excel)
>
>
>
> "FM" <spam(a)uce.gov> wrote in message
> news:uTwzkDSnKHA.1552(a)TK2MSFTNGP05.phx.gbl...
>> Can someone help me turn this ElseIf logic into a For Next loop:
>>
>> If CTR <= 50 Then
>> Spinner(1) = True
>> ElseIf CTR > 50 And CTR <= 100 Then
>> Spinner(2) = True
>> ElseIf CTR > 100 And CTR <= 150 Then
>> Spinner(3) = True
>> ElseIf CTR > 150 And CTR <= 200 Then
>> Spinner(4) = True
>> ElseIf CTR > 200 And CTR <= 250 Then
>> Spinner(5) = True
>> ElseIf CTR > 250 And CTR <= 300 Then
>> Spinner(6) = True
>> ElseIf CTR > 300 Then
>> Spinner(7) = True
>> End If
>>
>> Regards
>> FM
>>
>>
>

From: dpb on
FM wrote:
> Can someone help me turn this ElseIf logic into a For Next loop:
>
....sample code elided for brevity...

Don't need either.

1) set Spinner() = False

2) algorithm

idx = Max(Min(Int(CTR/50+1),7),1)
Spinner(idx) = True

--
From: dpb on
dpb wrote:
....

oops, typo..
> 2) algorithm
>
> idx = Max(Min(Int(CTR/50+1),7),1)
....

idx = Max(Min(Int(CTR/50)+1,7),1)

Note misplaced parenthesis, sorry.

--