Results 1 to 7 of 7

Thread: [RESOLVED] Join two text file

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2006
    Posts
    120

    Resolved [RESOLVED] Join two text file

    i have two text file(output.txt,sampleExtract.txt), i want combine the content of that two file to became one new file.How to do it?
    Attached Files Attached Files

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Join two text file

    You can do something like this:
    Code:
    Private Sub CombineFiles(filein1 As String, filein2 As String, fileout As String,)
    Dim sText1$, sText2$
    
        Open filein1 For Input As #1
            sText1 = Input(LOF(1), #1)
        Close #1
    
        Open filein2 For Input As #1
            sText2 = Input(LOF(1), #1)
        Close #1
    
        Open fileout For Output As #1
            Print #1, sText1
            Print #1, sText2
        Close #1
    
    End Sub

  3. #3
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Join two text file

    DOS has the COPY command to do just that. So you can do it thru code (as RhinoBull suggested) or shell to that command.

    The command is:

    Copy file1+file2 File3

  4. #4
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Join two text file

    Are you in taking the same course as this guy...

    http://www.vbforums.com/showthread.php?t=460249

  5. #5

    Thread Starter
    Lively Member
    Join Date
    May 2006
    Posts
    120

    Re: Join two text file

    Quote Originally Posted by RhinoBull
    You can do something like this:
    Code:
    Private Sub CombineFiles(filein1 As String, filein2 As String, fileout As String,)
    Dim sText1$, sText2$
    
        Open filein1 For Input As #1
            sText1 = Input(LOF(1), #1)
        Close #1
    
        Open filein2 For Input As #1
            sText2 = Input(LOF(1), #1)
        Close #1
    
        Open fileout For Output As #1
            Print #1, sText1
            Print #1, sText2
        Close #1
    
    End Sub
    it has an extra blank line on the end of "Output.txt"
    how to remove the blank line?

  6. #6
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Join two text file

    aren't you going to do any of the HW yourself???

  7. #7
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Join two text file

    Quote Originally Posted by junlo
    it has an extra blank line on the end of "Output.txt"
    how to remove the blank line?
    What do you mean by "extra"? The last 2 characters in the file are vbCR and vbLF, because the last thing done to the file was to print a line. If you want to eliminate that line, change Print #1, sText2 to Print #1, sText2;

    If there are 2 blank lines at the end, it's because there's an extra line at the end of the second file. Remove any occurrences of vbNewLine & vbNewLine (two of them in a row) from the end of sText2 before you print it to the output file.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width