Click here to Skip to main content
15,900,707 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dim temp() As Integer = {1, 2, 2, 3, 4}
Dim i As Integer

For count = 0 To temp.Count - 1
If (temp(i).ToString = temp(i + 1).ToString) Then
ListBox2.Items.Add(i)
End If
Next

It shows me error like index was out of boundary. Please help me out
Posted
Updated 3-Aug-14 12:08pm
v2
Comments
[no name] 3-Aug-14 18:06pm    
You really need to learn how to debug your own applications. What element would you expect to get from your temp array the first time through (temp(0 - 1))? What element is at temp(-1)?
[no name] 3-Aug-14 18:30pm    
And now that you have edited your code, the code you have presented here, will not produce the error described. And why would you compare temp(0) to temp(1) over and over?
Surajit Das 3-Aug-14 18:33pm    
so do you think i should use the while loop and use a counter and increment it

1 solution

Hi Surajit,
maybe you can use something like this:

Dim temp() As Integer = {1, 2, 2, 3, 4}
Dim i As Integer

For i = 0 To temp.Count - 2
If (temp(i) = temp(i + 1)) Then
ListBox2.Items.Add(temp(i))
End If
Next i

I Hope this is useful for you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900