Results 1 to 4 of 4

Thread: Frustration

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2003
    Location
    Tacoma, WA
    Posts
    13

    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

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Why you didn't specify the path ?

  3. #3
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    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 .

  4. #4
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    518
    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)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width