Solved

Append files using VB6

Posted on 2002-07-25
3
1,160 Views
Last Modified: 2007-11-27
My VB6 program reads one source text file and distributes its records to a number of output text files.  The amount and count totals for each output file are computed during this distribution process.

The totals need to be included in batch header records and the files appended together thus.  :  Batch header record + file + batch header record + file etc.

Can this be done with VB6 code without having to read and write individual records from one file to another?

Is there a Windows command that the program can call that will append one text file to another?

0
Comment
Question by:msdav
3 Comments
 
LVL 10

Expert Comment

by:aeklund
ID: 7178247
You can Shell out the "COPY" command, which is one way to do it..

example:

shell "copy " & file + file + file outputfile

The only other way that I know of is to read the contents of each file into variables, then write the entire thing out into your output file.
0
 
LVL 2

Accepted Solution

by:
damion69 earned 200 total points
ID: 7178248
you can append 1 file to another like this. I am currently using it as a trial version proggie for my software. It is designed to append to an exe but will work with any format. I got this code off of www.planetsourcecode.com not sure of the author or i would give him credit.

Private Sub AppendToExe(exefile$, filetoappend$)
Dim f As Integer
    Open filetoappend$ For Binary As #1
    filedata$ = String(LOF(1), " ")
    Get #1, , filedata$
    Close #1
    Open exefile$ For Binary As #1
    f = LOF(1)
    Seek #1, f + 1
    Put #1, , "treg" 'Change the identifier here
    Put #1, , filedata$
    Close #1
End Sub

Private Sub ExtractFromExe(exefile$)
    Open exefile$ For Binary As #1
    filedata$ = String(LOF(1), " ")
    Get #1, , filedata$
    Close #1
    pos = InStr(1, filedata$, "treg")'change identifier
    f$ = Mid$(filedata$, pos + 4) '+the len(identifier)
    MsgBox f$
End Sub
0
 

Author Comment

by:msdav
ID: 7178369
damion69 answers allows for both file copy and insertion of batch header record information as the "treg" variable - interesting solution!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now