Solved

On button click, copy content of text file (that has been displayed) and append to existing file

Posted on 2007-12-02
5
142 Views
Last Modified: 2010-04-23
I have a vb program that reads from a text file and displays the content in a textbox.  I need to add a button that allows the user to append this text to a different text file.  Can anyone help me with this?  
[code]
Private Sub showQuant()
        Dim inputFile As FileStream
        Dim reader As StreamReader
        Dim filename As String = "../../../Quant.txt"
        Dim inputstr As String
        Dim delim As Char() = {vbTab}
        inputFile = New FileStream(filename, FileMode.Open)
        reader = New StreamReader(inputFile)
        inputstr = reader.ReadLine()
        While inputstr <> Nothing
            Me.TextBoxBooks.Text = Me.TextBoxBooks.Text & inputstr
            inputstr = reader.ReadLine()
        End While
        reader.Close()
    End Sub
[\code]
0
Comment
Question by:lnewman0508
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 20392180
What version VB.Net?  2003 or 2005?
0
 

Author Comment

by:lnewman0508
ID: 20392711
VB.net 2005
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 50 total points
ID: 20393712
To append the contents of the file to your TextBox, you can simplify quite a bit:

    Private filename As String = "../../../Quant.txt"

    Private Sub showQuant()
        Me.TextBoxBooks.AppendText(My.Computer.FileSystem.ReadAllText(filename)
    End Sub

But you also said:

    "I need to add a button that allows the user to append this text to a different text file."

If you want to append the text from one file to another:

    My.Computer.FileSystem.WriteAllText("c:\theFileToAppendToHere", My.Computer.FileSystem.ReadAllText(filename), True)

Or if you wanted to append the current contents of your TextBox:

    My.Computer.FileSystem.WriteAllText("c:\theFileToAppendToHere", Me.TextBoxBooks.Text, True)
0
 
LVL 1

Expert Comment

by:Computer101
ID: 20632921
Forced accept.

Computer101
EE Admin
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question