[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
Re: Saving loading text boxes to file
Quote:
Originally Posted by
Donovan Also
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
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()
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
Re: Saving loading text boxes to file
Sorry, my mistake :blush:
it should be
Code:
SWriter.Write(TxtBx1.Text & "," & TxtBx2.Text)
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.
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()