|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
I have a file that I need to append to the end of another file. I'm trying to do it like this:
R1Copy = FreeFile() Open "M:\SCBMAIN\EMAIN" & i & "\" & Mkt & "1" & Year & "QU.o01" For Append As #R1Copy R2Copy = FreeFile() Open "M:\SCBMAIN\EMAIN" & i & "\" & Mkt & "2" & Year & "QU.o01" For Input As #R2Copy Do While Not EOF(R2Copy) Line Input #R2Copy, CopyRec 'Read a record Print #R1Copy, CopyRec Loop Problem is that after it runs the only thing in the file is the data that I'm appending(from R2Copy)...all the data that was supposed to be in there originally is gone. What am I doing wrong? Any help is totally appreciated...I'm lost! Thanks! |
|
#2
|
||||
|
||||
|
hold on.. I'm confused? You're saying that the only data in the second file (R2Copy) is the data that you're inputting, and that the original data is gone? If so, then try using "For Append" instead of "For Input" on your open statement. Is it doing so on the first file as well? Please clarify your question.
__________________
Fisherman "Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." - A.Einstein |
|
#3
|
|||
|
|||
|
I want to append R2Copy to the end of R1Copy. this is how I'm trying to do it:
R1Copy = FreeFile() Open "M:\SCBMAIN\EMAIN" & i & "\" & Mkt & "1" & Year & "QU.o01" For Append As #R1Copy R2Copy = FreeFile() Open "M:\SCBMAIN\EMAIN" & i & "\" & Mkt & "2" & Year & "QU.o01" For Input As #R2Copy Do While Not EOF(R2Copy) Line Input #R2Copy, CopyRec 'Read a record Print #R1Copy, CopyRec Loop After I run it and I check R1Copy, only data from R2Copy is there when I'm expecting data from both files to be there. I do use 'for append' in my open statement for R1Copy. Do you need more info? |
|
#4
|
||||
|
||||
|
I don't know.. I just started a new project, and put this in form load,.. I created two files "MyFile.txt" and "YourFile.txt". In those files, I typed the words "MyFile" and "YourFile", respectively... then I did this
Code:
Private Sub Form_Load() R1Copy = FreeFile() Open "C:\MyFile.txt" For Append As #1 R2Copy = FreeFile() Open "C:\YourFile.txt" For Input As #2 Do While Not EOF(R2Copy) EOF (1) Line Input #R2Copy, CopyRec 'Read a record Print #R1Copy, CopyRec Loop Close 1 Close 2 End Sub And it worked fine. You might try changing your file aliases to a simpler naming convention, and remember to close your files after you're finished with them. |
|
#5
|
|||
|
|||
|
Okay...I'll give it a try.
Thanks so much for your help! Joni |
|
#6
|
|||
|
|||
|
Fisherman's code is correct!It works fine!..Plz check whether the destination file exists,Open statemet can't create a new file if the file doesn't exist..
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > Appending data to a file |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|