Solved

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

Posted on 2007-12-02
5
139 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
ID: 20392180
What version VB.Net?  2003 or 2005?
0
 

Author Comment

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

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

803 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