Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old November 10th, 2003, 10:03 AM
happyjoni happyjoni is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: New Jersey
Posts: 3 happyjoni User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to happyjoni Send a message via Yahoo to happyjoni
Question Appending data to a file

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!

Reply With Quote
  #2  
Old November 10th, 2003, 10:08 AM
Fisherman's Avatar
Fisherman Fisherman is offline
Inherits Programmer.Slacker
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Aug 2003
Location: Between my Id and your Ego
Posts: 2,171 Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 9 h 1 m 37 sec
Reputation Power: 110
Send a message via ICQ to Fisherman Send a message via AIM to Fisherman
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

Reply With Quote
  #3  
Old November 10th, 2003, 10:17 AM
happyjoni happyjoni is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: New Jersey
Posts: 3 happyjoni User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to happyjoni Send a message via Yahoo to happyjoni
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?

Reply With Quote
  #4  
Old November 10th, 2003, 12:07 PM
Fisherman's Avatar
Fisherman Fisherman is offline
Inherits Programmer.Slacker
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Aug 2003
Location: Between my Id and your Ego
Posts: 2,171 Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 9 h 1 m 37 sec
Reputation Power: 110
Send a message via ICQ to Fisherman Send a message via AIM to Fisherman
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.

Reply With Quote
  #5  
Old November 10th, 2003, 12:20 PM
happyjoni happyjoni is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: New Jersey
Posts: 3 happyjoni User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to happyjoni Send a message via Yahoo to happyjoni
Okay...I'll give it a try.

Thanks so much for your help!
Joni

Reply With Quote
  #6  
Old November 10th, 2003, 11:26 PM
cleverpig cleverpig is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2003
Posts: 1,152 cleverpig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via MSN to cleverpig
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..

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > Appending data to a file


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway