tags:

views:

75

answers:

2

can someone please help me. why does this return an error:

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

    Dim split As String() = temp_string.Split(",")
    For Each s As String In split
        If s.Trim() <> "" Then
            stuff(i) = s
            i = i + 1
        End If
    Next s

the stuff(i)=2 line is returning the mentioned error

+1  A: 

Looks like it could be an off by one error. What is i initialized to? 0 or 1?

Chris Kloberdanz
+4  A: 

Use stuff.Add(i) instead of that, you accessing not an array but a list which doesn't have an index upon creation only after you assign values you can access it's indexes as an array.

eugeneK
+1. Deleted my own (incorrect) post and am throwing in my support for @eugeneK, who reads the question better than I do, apparently.
David Stratton
Actually 99% of the time i do not read the question so my answers are random...
eugeneK
excellent because my questions are completely random too
I__
seems that one of those rare cases when two random number match, happens !!!
eugeneK