then check if i = 6 or i>=3 or i >= 2

Solved

Posted on 2009-02-17

Hello,

I have an array that 38 elements in it - Array(38). The value can be either 1 or 0. For array elements 1 through 31 in the array, I have to determine if the next consecutive 6, 3, or 2 elements are also valued at 1. Once the array element gets past 31, it does not need to check elements 32-38.

I.e. IF Array(1)=1, do Array(2), Array(3), Array(4), Array(5), Array(6), Array(7) all = 1 ?

If not, IF Array(1) = 1 do Array(2), Array(3), Array(4) all = 1 ?

If not, if Array(1) = 1 do Array(2), Array(3) = 1 ?

If 7 consecutive elements are true, then the 4 and 3 check do not need to be done. However, if 7 consecutive is not true, then I need to check for consecutive 4, then consecutive 3.

I can do this with a series of FOR .. NEXT loops but it is not very efficient because all

I have an array that 38 elements in it - Array(38). The value can be either 1 or 0. For array elements 1 through 31 in the array, I have to determine if the next consecutive 6, 3, or 2 elements are also valued at 1. Once the array element gets past 31, it does not need to check elements 32-38.

I.e. IF Array(1)=1, do Array(2), Array(3), Array(4), Array(5), Array(6), Array(7) all = 1 ?

If not, IF Array(1) = 1 do Array(2), Array(3), Array(4) all = 1 ?

If not, if Array(1) = 1 do Array(2), Array(3) = 1 ?

If 7 consecutive elements are true, then the 4 and 3 check do not need to be done. However, if 7 consecutive is not true, then I need to check for consecutive 4, then consecutive 3.

I can do this with a series of FOR .. NEXT loops but it is not very efficient because all

4 Comments

then check if i = 6 or i>=3 or i >= 2

Array(1) = 1

Array(2) = 1

Array(3) = 0

Array(4) = 0

Array(5) = 1

Array(6) = 1

Array(7) = 1

If i >=3 or i >=2 is true in this scenario, but I need to find out for consecutive elements

Array(1) = 1

Array(2) = 1

Array(3) = 1

Array(4) = 1

Array(5) = 0

Array(6) = 0

The above would be true for the 3 consecutive and 4 consecutive but false for the 7 consecutive.

so if

Array(1) = 1

Array(2) = 1

Array(3) = 0

Array(4) = 0

Array(5) = 1

Array(6) = 1

Array(7) = 1

you would stop at Array(3) = 0

(°v°)

```
Dim A(1 To 38) As Integer
Dim i As Integer
Dim n As Integer
' fill array ( p(1) = 80% )
For i = 1 To 38
A(i) = IIf(Rnd() < 0.2, 0, 1)
Next i
' count runs
For i = 38 To 1 Step -1
If A(i) Then n = n + 1: A(i) = n Else n = 0
Next i
' display
For i = 1 To 38
Debug.Print "A(" & i & ") = " & A(i) & ": ";
Select Case A(i)
Case Is >= 7: Debug.Print "run+6"
Case Is >= 4: Debug.Print "run+3"
Case Is >= 3: Debug.Print "run+2"
Case Else: Debug.Print
End Select
Next i
```

By clicking you are agreeing to Experts Exchange's Terms of Use.

Title | # Comments | Views | Activity |
---|---|---|---|

add text to end of existing text in file | 16 | 54 | |

matchUp challenge | 9 | 48 | |

mapBully challenge | 6 | 50 | |

Path of Workbook | 3 | 30 |

A short article about a problem I had getting the GPS LocationListener working.

Join the community of 500,000 technology professionals and ask your questions.

Connect with top rated Experts

**18** Experts available now in Live!