dtucker
asked on
Merging 2 random files
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
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
ASKER
Ok I made the change and all but the first record in the secondfile gets merged into the finalfile.
Any thoughts...
Any thoughts...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
finalcurrentrecord = finallastrecord + 1 and try. rest all looks fine for me.