none
Text File into 2-D array Visual Studio 2010 RRS feed

  • Question

  • Hello I am trying to input a text file of figures into a 2-dimensional array. I want to do this so I will then perform percent changes on the respective columns. The text file contains columns and then numerous rows for each columns each number is separated with a tab. The text file looks something like this.
    2.2 5.5
    3.7 6.3
    9.2 9.1
    5.4 10.2
    2.5 4.55
    So I need to be able to input the text file, turn it into an array and then calculate the percent change for each column and find the total percent change. Such as the change to 2.2 to 3.7 then 3.7 to 9.2. Then the total percent change for that column. So the program will create an output file with the percent changes per row for the column for each column and the total percent change for the each column.

     

    This is what I have so far for importing the textfile into a listbox. From here am I able to preform calculations? I'm getting an error that my data file doesn't fit into an array.

     

      Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalc.Click

            Try

                Dim reader As New Microsoft.VisualBasic.FileIO.TextFieldParser("C:\test.txt")

                reader.TextFieldType = FileIO.FieldType.Delimited

                reader.SetDelimiters("  ")


                While Not reader.EndOfData

                    Dim Fields() As String = reader.ReadFields

                    ListBox.Items.Add(Fields(0))


                End While


                reader.Close()

            Catch ex As Exception

                MessageBox.Show(Err.Description)

            End Try

        End Sub

     

    Monday, November 29, 2010 2:46 AM

Answers

All replies