Hi All, I'm trying to read data from a text file into an array. The text file (a test) looks like this:
1
2
3
4
5
6
7
8
9
And the code I've got so far looks like this:
Dim readerVar As StreamReader
Dim dr As DialogResult
Dim i As Integer
Dim WorkString As String = "a"
dr = dlgOpen.ShowDialog()
If dr = DialogResult.OK Then
readerVar = New StreamReader(dlgOpen.FileName)
i = 0
While readerVar.Peek <> -1 ' Loop to read number of lines in file
WorkString = readerVar.ReadLine() ' Get line
i = i + 1 ' Count number of lines in file
End While
ReDim readArray(i)
readerVar = New StreamReader(dlgOpen.FileName)
i = 0
While readerVar.Peek <> -1
WorkString = readerVar.ReadLine() ' Get line
readArray(i) = Double.TryParse(WorkString, readArray(i))
i = i + 1
End While
txtBox.Text = readArray(0)
readerVar.Close()
Else
End If
(I know, terrible isn't it!)
The array now reads something like this:
-1
-1
-1
-1
-1
-1
-1
0
0
Can anyone help me?
Andy
PS does anyone have any code to draw a simple graph from a 1D array?