Solved

Merging 2 random files

Posted on 1998-10-08
4
173 Views
Last Modified: 2010-04-30
I know I asked this question before but I need some clarity with my code.
Below is my code, which dosn't work.
I basically am taking the firstfile and copying it as the finalfile, then I open the secondfile and try toget each record and put it at the end of the newly created finalfile.
But for some reason it is not working.
What am I doing wrong?
Dim finalcurrentrecord As Long
Dim finallastrecord As Long

lblmerge.Visible = True
firstfile$ = txtfirst.Text
secondfile$ = txtsecond.Text
finalfile$ = txtfinal.Text
Close
FileCopy firstfile$, finalfile$
recordlen = Len(primequote)
    filenum = 1
    Open finalfile$ For Random As filenum Len = recordlen
    finallastrecord = FileLen(finalfile$) / recordlen
    finalcurrentrecord = finallastrecord
   
recordlen = Len(primequote)
    filenum = 2
    Open secondfile$ For Random As filenum Len = recordlen
    currentrecord = 1
    lastrecord = FileLen(secondfile$) / recordlen
    If lastrecord = 0 Then
    lastrecord = 1
    End If
    currentrecord = 1
For recnum = 1 To lastrecord
Get #2, currentrecord, primequote
Put #1, finalcurrentrecord, primequote
recnum = recnum + 1
currentrecord = currentrecord + 1
finalcurrentrecord = finalcurrentrecord + 1
Next
END OF MY CODE

0
Comment
Question by:dtucker
  • 2
4 Comments
 
LVL 3

Expert Comment

by:vmano
ID: 1438891
change the line finalcurrentrecord = finallastrecord to this:
finalcurrentrecord = finallastrecord + 1 and try. rest all looks fine for me.
0
 

Author Comment

by:dtucker
ID: 1438892
Ok I made the change and all but the first record in the secondfile gets merged into the finalfile.
Any thoughts...

0
 
LVL 18

Accepted Solution

by:
deighton earned 0 total points
ID: 1438893

Heres a function for you to try - Good Luck

Public Sub MergeFiles(ByVal sFile1 As String, ByVal sFile2 As String, ByVal sFile3 As String, ByVal iLen As Long)

'APPEND FILE1 TO FILE 2 TO GIVE FILE3 - RECORDLENGTH = ILEN

    Dim iFile2 As Long, ifile3 As Long
    Dim iLength1 As Long
    Dim iStart As Long
   
    Dim sBuf As String

    FileCopy sFile1, sFile3
   
    ifile3 = FreeFile
   
    Open sFile3 For Binary As ifile3
   
    iLength1 = LOF(ifile3)
   
    iStart = iLength1 + 1
   
    iFile2 = FreeFile
    Open sFile2 For Binary As iFile2
   
    For c = 1 To LOF(iFile2) \ iLen
           
        sBuf = String(iLen, " ")
                   
        Get #iFile2, , sBuf
       
        Put #ifile3, iStart, sBuf
       
        iStart = iStart + iLen
       
    Next
   
    Close #iFile2, #ifile3
   
       
End Sub


0
 
LVL 3

Expert Comment

by:vmano
ID: 1438894
try this: Get #2, , primequote in the loop and comment out all the code for currentrecord. but i am not sure why it's happening.

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

895 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

11 Experts available now in Live!

Get 1:1 Help Now