-
Nov 6th, 2016, 04:43 PM
#1
Thread Starter
Junior Member
[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
-
Nov 6th, 2016, 05:13 PM
#2
Re: Saving loading text boxes to file
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)
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()
Last edited by 4x2y; Nov 6th, 2016 at 05:19 PM.
-
Nov 6th, 2016, 05:36 PM
#3
Thread Starter
Junior Member
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
-
Nov 6th, 2016, 05:43 PM
#4
Re: Saving loading text boxes to file
Sorry, my mistake
it should be
Code:
SWriter.Write(TxtBx1.Text & "," & TxtBx2.Text)
-
Nov 6th, 2016, 05:57 PM
#5
Thread Starter
Junior Member
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.
-
Nov 6th, 2016, 07:10 PM
#6
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|