Read Text File and plot XY Chart

  • Thread starter Thread starter Carlton_Banx
  • Start date Start date
C

Carlton_Banx

Guest
Hello,

Im fairly new to programming and visual basic 2010, for a project Im undertaking I need to be able to plot an XY chart from a tab delimited text file. The input text file data looks some what like this:

0.0000E+0 -144.0000E-3 -151.5304E-3
24.9938E-12 -148.0000E-3 -151.6275E-3
49.9875E-12 -150.0000E-3 -151.7454E-3
74.9813E-12 -150.0000E-3 -151.8030E-3

This data carries on for a very long time, I need to plot the first column as X and the second column as Y and completely ignore the third column. So far my code looks like this:

Private Sub pltbtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pltbtn.Click

Using MyReader As New Microsoft.VisualBasic.FileIO.
TextFieldParser(<FileName>)
MyReader.TextFieldType =
Microsoft.VisualBasic.FileIO.FieldType.Delimited
MyReader.Delimiters = New String() {vbTab}
Dim currentRow As String()
While Not MyReader.EndOfData
Try
currentRow = MyReader.ReadFields()
Chart1.Series(0).Points.AddXY(currentRow(0), currentRow(1))
Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
MsgBox("Line " & ex.Message &
" is invalid. Skipping")
End Try
End While
End Using

This doesnt seem to work and I dont know why! Any help would be much appreciated.

Thanks

Continue reading...
 
Back
Top