Solved

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

Posted on 2007-12-02
5
143 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

707 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