Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Beginning VB 6
|
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 28th, 2007, 10:48 AM
Authorized User
 
Join Date: Dec 2006
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default code to read two text files, concatenate one......

hello,
what would be the code that would allow me to read in two text files, concatenate the second one to the end of the first one, then output the file as a new third text file?
thanks in advance,
david

 
Old March 28th, 2007, 10:58 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there..

you could investigate the filesystemobject that would allow you to open a file as a textstream and then you could open the two files, and read one after another into the third file....

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
 
Old April 18th, 2007, 03:24 PM
Authorized User
 
Join Date: Dec 2006
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

this code I was given by a user on another site works well for me, at least it did well in a test run with the largest text files I'll probably be doing with.
thanks,
david
Code:
Sub JoinFiles(ByVal File1 As String, ByVal File2 As String, ByVal SaveAs As String)
    Dim intFF As Integer, strBuffer As String
    Dim lonL1 As Long, lonL2 As Long

    lonL1 = FileLen(File1)
    lonL2 = FileLen(File2)

    'Allocate space for the 2 files.
    strBuffer = Space$(lonL1 + lonL2)

    intFF = FreeFile

    Open File1 For Input As #intFF
        Mid$(strBuffer, 1, lonL1) = Input(LOF(intFF), intFF)
    Close #intFF

    intFF = FreeFile

    Open File2 For Input As #intFF
        Mid$(strBuffer, lonL1 + 1) = Input(LOF(intFF), intFF)
    Close #intFF

    intFF = FreeFile

    'Write new file.
    Open SaveAs For Output As #intFF
        Print #intFF, strBuffer
    Close #intFF

    strBuffer = ""
End Sub





Similar Threads
Thread Thread Starter Forum Replies Last Post
how to read files in evc++ iriskab Visual C++ 1 September 1st, 2006 04:19 AM
Concatenate TEXT Type Value 1kHz SQL Language 5 December 31st, 2004 01:29 AM
Concatenate different files into one single report safecoder Crystal Reports 1 October 12th, 2004 03:37 PM
How to read multiple text files into excel? Together Excel VBA 4 March 5th, 2004 06:26 PM
How to read text files from CD? Alex1024 VB How-To 2 November 3rd, 2003 12:50 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.