Solved

Merging 2 random files

Posted on 1998-10-08
4
178 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
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…
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…
Suggested Courses
Course of the Month6 days, 14 hours left to enroll

623 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