-
Frustration
I'm trying to simply open streamreader to read a SIMPLE text file and display it. I keep getting an error saying it can't find my text file. What's up with this? I've put the text file in the bin folder like my teacher told me to and I've also tried using the exact path to the file. Any suggestions?
Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
Dim numOfStudents As Integer = 1
Dim numOf50Less As Integer = 0
Dim totalOfGrades As Single
Dim is50Less As Boolean = False
'Open the stream reader
Dim Name As String
Dim Grade As Integer
Dim Data As IO.StreamReader = IO.File.OpenText("Data.TXT")
'Go through each item in the file in which the number of grades
'is the same as the number of students and all numbers and grades
'are mixed up
lstDisplay.Items.Clear()
Do While Data.Peek <> -1
Name = CStr(Data.ReadLine())
Grade = CInt(Data.ReadLine())
lstDisplay.Items.Add(Name & Grade)
Loop
'Close th streamreader
Data.Close()
End Sub
End Class
-
Why you didn't specify the path ?
-
Hmm , I've tried you code and worked fine except some conversion problems from string to int (based on sample I typed). That's right you can specify file name only as you did . I can't see other problems here .
-
I feel that it is a good idea to always specify the full path to the file when working with IO.*, whether you are using OpenFileDialog or CurDir() or whatever. When you specify the full path, exactly what exception is thrown? I use exactly the same algo for reading text files and it works fine normally (although I use CurDir() or some like function to get a full path)