Graph Data

  • Thread starter Thread starter Tom Nowak
  • Start date Start date
T

Tom Nowak

I am trying to create a graph based on data in a CSV file. The routine below
gets one value, but i want to keep reading the file, and string all the data
(comma delimited) together into the array, then do the graph processing. The
code below only get the last value in the file. How do I get all the data in
the file? The commented out code at the top works, but I do not want to
hardcode values. Please help:

Function GetBarValues()

'barValue = New Integer() {18, 45, 163, 226, 333, _
' 3, 183, 305, 329, 73, _
' 271, 132, 348, 272, 64}

'Return barValue

Try

Dim textin As New StreamReader(New FileStream(path,
FileMode.OpenOrCreate, FileAccess.Read))
Response.Write("System Stats<br>")
Response.Write("<br>")
Response.Write("<table>")
Do While textin.Peek <> -1
Dim i As Integer
Dim row As String = textin.ReadLine
Dim columns() As String = row.Split(CChar(","))
For i = 0 To columns.Length - 1
barValue = New Integer() {CInt(columns(i))}
Next
Loop
textin.Close()
Catch ex As Exception
lblError.Text = "The file could not be read: " & _
ex.Message
End Try
Return barValue

End Function
 
Hi,

My VB.Net is weak but i think Your problem is here :
For i = 0 To columns.Length - 1
barValue = New Integer() {CInt(columns(i))}
Next
In there You always overwrite the previously collected value with the new
one, so barvalue will contain only the last value of the last line.

One way to solve this could be to :
1., create a new instance of a List<int> (lets call it tempList), at the
start of Your method
Dim tempList As List(Of Integer) = New List(Of Integer)
2, instead of the above 3 lines, append the values in the columns array to
the list
For Each value As String In columns
tempList.Add(CInt(value))
Next
3., at the end of Your method convert the list to array
barValue = tempList.ToArray

As I said before, this is one way to do, other ways exists also. Please
forgive me if i made some syntax mistake, as i said my VB.Net knowledge is
weak.

Hope You find this useful.
-Zsolt

"Tom Nowak" <[email protected]> az alábbiakat írta a
következő üzenetben
news:[email protected]...
 
Thanks for the advice. The syntax is a little off, but I will give this
concept a shot. Thanks again.
 
Back
Top