I am working with a Windows forms application that allows a user to open a file, which the program reads using a textreader object. I can't assign the text reader object to the file until the open file dialog completes, so I am unable to use the text reader object outside of the 'open file' button click event. I need to be able to use it in a function that is called from a timer tick event. Here is the basic setup: (this is very abbreviated to just show the structure)
The program builds, but crashes as soon as the form loads and tells me i need to use 'the "new" keyword to create an object instance' of fsReader inside the GetNextLine function. I am assuming that if i do that I will lose the current line I am on in the file and start over at the beginning, which I do not want.
Come somebody give me some advice on how to use the instance defined in the open file sub?
Code:
Partial Class Form1
Dim fs As System.IO.FileStream
Dim fsReader
----------------------------------
Private Sub btnOpen_Click()
fs = dlgOpenFile.OpenFile()
fsReader = New System.IO.StreamReader(fs)
End Sub
----------------------------------
Private Sub GetNextLine()
line = fsReader.ReadLine()
End Sub
----------------------------------
Private Sub Timer1_Tick()
GetNextLine()
End Sub
----------------------------------
End Class
The program builds, but crashes as soon as the form loads and tells me i need to use 'the "new" keyword to create an object instance' of fsReader inside the GetNextLine function. I am assuming that if i do that I will lose the current line I am on in the file and start over at the beginning, which I do not want.
Come somebody give me some advice on how to use the instance defined in the open file sub?