Solved

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

Posted on 2007-12-02
5
136 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
  • 2
5 Comments
 
LVL 85

Expert Comment

by:Mike Tomlinson
Comment Utility
What version VB.Net?  2003 or 2005?
0
 

Author Comment

by:lnewman0508
Comment Utility
VB.net 2005
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 50 total points
Comment Utility
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
Comment Utility
Forced accept.

Computer101
EE Admin
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
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…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now