Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 149,554 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,614 people online right now. Registration is fast and FREE... Join Now!




Save and Open Multiple text boxes

 
Reply to this topicStart new topic

Save and Open Multiple text boxes

fergy1307
27 Nov, 2007 - 07:27 PM
Post #1

New D.I.C Head
*

Joined: 27 Nov, 2007
Posts: 3


My Contributions
I am trying to save multiple text boxes to a text file and open them back up in that box it was origanaly in. i have this code but when it saves to the text file it all goes to one line and then opens in only one of the text boxes
CODE

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim Save As New SaveFileDialog()
        Dim myStreamWriter As System.IO.StreamWriter

        Save.Filter = "Plain Text Files (*.txt)|*.txt|All files (*.*)|*.*"
        Save.CheckPathExists = True
        Save.Title = "Save"
        Save.ShowDialog(Me)

        Try
            myStreamWriter = System.IO.File.AppendText(Save.FileName)
            myStreamWriter.Write(TextBox1.Text)
            myStreamWriter.Write(TextBox2.Text)
            myStreamWriter.Flush()
        Catch ex As Exception
            ' Do Nothing
        End Try
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim Open As New OpenFileDialog()
        Dim myStreamReader As System.IO.StreamReader

        Open.Filter = "Plain Text Files (*.txt)|*.txt|All files (*.*)|*.*"
        Open.CheckFileExists = True
        Open.Title = "Open"
        Open.ShowDialog(Me)
        Try
            Open.OpenFile()
            myStreamReader = System.IO.File.OpenText(Open.FileName)
            TextBox1.Text = myStreamReader.ReadToEnd()
            TextBox2.Text = myStreamReader.ReadToEnd()
        Catch ex As Exception

        End Try
    End Sub
End Class

User is offlineProfile CardPM
+Quote Post

Jayman
RE: Save And Open Multiple Text Boxes
27 Nov, 2007 - 07:48 PM
Post #2

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 7,306



Thanked: 66 times
Dream Kudos: 500
Expert In: Everything

My Contributions
Moved to VB.NET forum.

Use the WriteLine method to write the data to your text file. And then use the ReadLine method to read the data back into the textbox.

Not sure why you are trying to read the entire text file into each textbox.
User is online!Profile CardPM
+Quote Post

kaymaf
RE: Save And Open Multiple Text Boxes
1 Dec, 2007 - 03:18 PM
Post #3

New D.I.C Head
*

Joined: 3 Oct, 2007
Posts: 24


My Contributions
i think the problem is that you used
myStreamWriter.Write(TextBox1.Text)
myStreamWriter.Write(TextBox2.Text)

try this

myStreamWriter.WriteLine(TextBox2.Text)

hope this work
kaymaf

This post has been edited by kaymaf: 1 Dec, 2007 - 03:18 PM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 09:53PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month