RicRev
RicRev

Reputation: 29

Find index on array using content

I have create an array of integers.

Dim EnemyLevel() as Integer = {1,2,2,3}

Let's say I wanted to get the position of every item that included '2', that'd be EnemyLevel(1) and EnemyLevel(2), what's the function to do that?

I'm supossed to use Array.IndexOf(EnemyLevel(),2) but how do I store the results?

Upvotes: 0

Views: 33

Answers (1)

anonyMouse
anonyMouse

Reputation: 56

You run the array in a For Loop. And check if any of the indices contain '2'

Array1 = Array(1,2,2,4)    
For i=0 to UBound(Array1)    
   If Array1(i) = 2 Then    
      msgbox i    
   End If    
Next

Upvotes: 1

Related Questions