I am thinking I will need to read the complete text file first to count how many lines are in it, then what ever is put in the text box it will take that many lines of data from the text file and populate the chart. For this to work correctly it would have to read the lines of the file back wards.(last line of file would be the first line..) e.g. textbox1.text = "7" then the chart would show only the last 7 lines of my data.
I was looking up examples of Counting the lines in the file, I think I am close here...
Dim fso As New FileSystemObject Dim txt As TextStream Set txt = fso.OpenTextFile(ReadChart, ForReading) txt.ReadAll Textbox2.text & txt.Line & " line(s)." txt.Close Set fso = Nothing
I need someone to guide me what I need to read up on to get this done step by step. I also found this http://www.dreaminco...from-text-file/ and it looks like what I need but just for the first part.
I think I need to place something in this part of the code to tell StreamReader how many lines to read...?
While ChartValues.Peek <> -1 Dim values() As String = ChartValues.ReadLine.Split(","c) s.Points.AddXY(values(0), values(1)) t.Points.AddXY(values(0), values(2)) u.Points.AddXY(values(0), values(3)) End While
This is my current code below
Dim ReadChart As String ReadChart = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\Charts\chart.txt" Dim ChartValues As StreamReader = New StreamReader(ReadChart) Chart1.Series.Clear() Chart1.Titles.Add("Progress Chart") 'Create a new series and add data points to it. Dim s As New Series Dim t As New Series Dim u As New Series ' Name of the series s.Name = "Weight" t.Name = "Oxygen" u.Name = "Heartrate" 'Change to a line graph. s.ChartType = SeriesChartType.Spline t.ChartType = SeriesChartType.Spline u.ChartType = SeriesChartType.Spline While ChartValues.Peek <> -1 Dim values() As String = ChartValues.ReadLine.Split(","c) s.Points.AddXY(values(0), values(1)) t.Points.AddXY(values(0), values(2)) u.Points.AddXY(values(0), values(3)) End While 'Add the series to the Chart1 control. Chart1.Series.Add(s) Chart1.Series.Add(t) Chart1.Series.Add(u)
Thanks again for reading this, I started this new thread I hope it is ok.
This post has been edited by cwd: 24 March 2011 - 06:08 AM