Out of Bounds Error :S

Elbob

Member
Joined
Apr 28, 2009
Messages
18
Programming Experience
1-3
Hi.

I keep getting an out of bounds error on the following code.

VB.NET:
      Using MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser(csvfile.Text)
            MyReader.TextFieldType = FileIO.FieldType.Delimited
            MyReader.SetDelimiters(",")

            Dim currentRow As String()
            Dim currentField As String

            While Not MyReader.EndOfData
                Try
                    currentRow = MyReader.ReadFields()

                    For Each currentField In currentRow

                        Dim Fields(2) As String
                        Fields = Split(Text, ",")
                        Fields(0) = currentRow(0)
                        Fields(1) = currentRow(1)

                        MsgBox(Fields(0))
                        MsgBox(Fields(1))


                    Next
                Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
                    MsgBox("Line " & ex.Message & _
                     "is not valid and will be skipped.")
                End Try
            End While
        End Using

Can anyone see where I'm going wrong? Any help would be appreciated.

Thankyou
 
Comment out the following:

VB.NET:
Fields = Split(Text, ",")

This line essentially ends up taking Me.Text, which limits the fileds array to having only 1 item.
 
Back
Top