Results 1 to 3 of 3

Thread: StreamReader not reading entire file

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2021
    Posts
    41

    StreamReader not reading entire file

    I am having a serious problem where StreamReader will not read the entire file. If I set the path of the save file to the smae place that the executable is in, the StreamReader will read the whole file. If I have the location set to anywhere else, the StreamReader will only read a tiny bit of the file.
    Code:
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            Try
                
                Dim path As String = My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\saves.txt"
                Dim read As New System.IO.StreamReader(path, True)
                Dim saves As String = read.ReadToEnd
    
    
                calc = saves.Split("!")(0)
                cps = saves.Split("!")(1)
                pquantity = saves.Split("!")(2)
                pprice = saves.Split("!")(3)
    
                fquantity = saves.Split("!")(4)
                fprice = saves.Split("!")(5)
    
                miquantity = saves.Split("!")(6)
                miprice = saves.Split("!")(7)
    
                micquantity = saves.Split("!")(8)
                micprice = saves.Split("!")(9)
    
                piquantity = saves.Split("!")(10)
                piprice = saves.Split("1")(11)
    
                vquantity = saves.Split("!")(12)
                vprice = saves.Split("!")(13)
    
                rquantity = saves.Split("!")(14)
                rprice = saves.Split("!")(15)
    
                lquantity = saves.Split("!")(16)
                lprice = saves.Split("!")(17)
    
                mquantity = saves.Split("!")(18)
                mprice = saves.Split("!")(19)
    
                bquantity = saves.Split("!")(20)
                bprice = saves.Split("!")(21)
    
                read.Close()
    
            Catch ex As Exception
            End Try
            NumberFormat()
    
        End Sub
    
        Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
         
            Dim path As String = My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\saves.txt"
            Dim W As New System.IO.StreamWriter(path, True)
            W.Write(score & "!" & cps & _
                    "!" & pquantity & "!" & pprice _
                    & "!" & fquantity & "!" & fprice _
                   & "!" & miquantity & "!" & miprice _
                   & "!" & micquantity & "!" & micprice _
                   & "!" & piquantity & "!" & piprice _
                   & "!" & vquantity & "!" & vprice _
                   & "!" & rquantity & "!" & rprice _
                   & "!" & lquantity & "!" & lprice _
                   & "!" & mquantity & "!" & mprice _
                   & "!" & bquantity & "!" & bprice)
            W.Close()
        End Sub

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: StreamReader not reading entire file

    You've duplicated this information in another thread and also indicated in that thread that the issue is actually writing the file rather than reading it. Please provide a FULL and CLEAR explanation of the actual problem. Also, why are we just seeing this complex code? Why haven't you tried simpler code and built it up bit by bit to find out where it actually breaks? You can do some actual testing and debugging for yourself. That's called software development.

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: StreamReader not reading entire file

    Instead of splitting 20 and odd times...

    Code:
    calc = saves.Split("!")(0)
    cps = saves.Split("!")(1)
    
    pquantity = saves.Split("!")(2)
    
    ... etc
    Just split once...

    Code:
    Dim a() As String = saves.Split("!")
    
    calc = a(0)
    cps = a(1)
    
    pquantity = a(2)
    
    ... etc
    Last edited by .paul.; Oct 10th, 2021 at 01:42 AM.

Tags for this Thread

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