[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 146
  • Last Modified:

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

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
lnewman0508
Asked:
lnewman0508
  • 2
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
What version VB.Net?  2003 or 2005?
0
 
lnewman0508Author Commented:
VB.net 2005
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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
 
Computer101Commented:
Forced accept.

Computer101
EE Admin
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now