Alex Gordon
Alex Gordon

Reputation: 60691

vb.net: index out of range

Public extreme_foods As New System.Collections.ArrayList()
Dim i As Integer
i = 1

For Each s In split2
    extreme_foods(i) = s
    i = i + 1
Next 

anyone know why extreme_foods(i)=s is giving INDEX OUT OF RANGE??

Upvotes: 0

Views: 1235

Answers (2)

Dana
Dana

Reputation: 32957

If I understand your code, you're trying to add elements to the ArrayList. I think you'd want to use the Add() method. So something like:

For Each s In split2
    extreme_foods.Add(s)
Next

I'm assuming that split2 is a Collection you've created somewhere else in your code.

Upvotes: 1

dotjoe
dotjoe

Reputation: 26940

because there are no items in it. try extreme_foods.Add(s)

Upvotes: 3

Related Questions