dcsimg
Results 1 to 6 of 6

Thread: [RESOLVED] Saving loading text boxes to file

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2005
    Location
    England, Devon, Honiton
    Posts
    18

    Resolved [RESOLVED] Saving loading text boxes to file

    Dear all.

    I have searched over 40 Youtubes and msdn to no avail.
    I am trying to save more than one text box to a file, and of course load after.

    Bla Bla

    If DialogResult = DialogResult.OK Then
    Dim SWriter As StreamWriter = New StreamWriter(SaveFileDialog.FileName)

    SWriter.Write(TxtBx1.Text) comment 12345
    SWriter.Write(TxtBx2.Text) comment absdr

    SWriter.Close()
    End If
    Hope to save this in text file as 12345,absdr

    Hope to load this back to the text boxes on load event. so TxtBx1.Text is 12345 and TxtBx2.Text is absdr

    Would be fantastic to see the code / syntax of this.

    Thanks.
    Donovan

  2. #2
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,565

    Re: Saving loading text boxes to file

    Quote Originally Posted by Donovan Also View Post
    Hope to save this in text file as 12345,absdr


    Save like this
    Code:
    SWriter.Write(TxtBx1.Text) & "," & SWriter.Write(TxtBx2.Text)

    Quote Originally Posted by Donovan Also View Post
    Hope to load this back to the text boxes on load event. so TxtBx1.Text is 12345 and TxtBx2.Text is absdr
    Read like this
    Code:
            Dim SReader As StreamReader = New StreamReader("path\to\your\file")
    
            Dim r() As String = SReader.ReadToEnd.Split(",")
            TxtBx1.Text = r(0)
            TxtBx2.Text = r(1)
    
            SReader.Close()
    Last edited by 4x2y; Nov 6th, 2016 at 05:19 PM.



  3. #3

    Thread Starter
    Junior Member
    Join Date
    Feb 2005
    Location
    England, Devon, Honiton
    Posts
    18

    Re: Saving loading text boxes to file

    Hi Thanks for that.

    I have put this save code in and am getting an error message on the first & "end of statement expected" SWriter.Write(TxtBx1.Text) & "," & SWriter.Write(TxtBx2.Text)
    Any further advice?
    Cheers

  4. #4
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,565

    Re: Saving loading text boxes to file

    Sorry, my mistake

    it should be
    Code:
    SWriter.Write(TxtBx1.Text & "," & TxtBx2.Text)



  5. #5

    Thread Starter
    Junior Member
    Join Date
    Feb 2005
    Location
    England, Devon, Honiton
    Posts
    18

    Re: Saving loading text boxes to file

    Hi 4x2y

    I have solved this.

    The syntax is in fact :- SWriter.Write(TxtBx1.Text & ",")
    SWriter.Write(TxtBx2.Text)

    The load works fine.

    Very much apreciated.

  6. #6
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,565

    Re: [RESOLVED] Saving loading text boxes to file

    Another more simple way is to write each TextBox.Text to a line

    Write
    Code:
            Dim SWriter As StreamWriter = New StreamWriter("path\to\your\file")
    
            SWriter.WriteLine(TxtBx1.Text)
            SWriter.WriteLine(TxtBx2.Text)
    
            SWriter.Close()
    Read
    Code:
                    Dim SReader As IO.StreamReader = New StreamReader("path\to\your\file")
    
            TxtBx1.Text = SReader.ReadLine
            TxtBx2.Text = SReader.ReadLine
            SReader.Close()



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
  •  



Featured


Click Here to Expand Forum to Full Width