Solved

Append files using VB6

Posted on 2002-07-25
3
1,168 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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Concatenate 2 userform comboboxes to a userform text box 4 65
Visual Basic Excel Formatting error 4 109
using Access 8 72
TT Auto Dashboard 13 92
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

825 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