Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using the Put Statement!!

Status
Not open for further replies.

99mel

Programmer
Oct 18, 1999
379
0
0
GB
When you use the Put Statement and the text file already contains data (text) it overwrites the data at the position you state. Can I go to a position in a text file and overwrite a certain number but leave the data in front of this number there. The number that I want to write to the file might be longer than the number already in the position.<br>
<br>
Thanks for any help :)
 
It sounds like you want to insert into the middle of a text file, depending on whether there's enough room for the stuff you want to Put there.<br>
<br>
Not an easy question, I'm afraid.<br>
<br>
Once you've determined that your data won't fit, you have to go through the following steps:<br>
1) Copy all data from your original file (file 'A') up to the start of the position you want to insert to, to file 'B'.<br>
2) Append your data to file 'B'<br>
3) Back in file 'A', skip over the data that you would've overwritten, then append the rest of file 'A' to file 'B'<br>
4) Delete file 'A', and rename file 'B' to 'A'.<br>
<br>
Ugly, really ugly, but I don't know any other way to handle it. Maybe someone else here has a better suggestion. Of course, the &quot;correct&quot; answer would be to redesign the file layout so this doesn't happen, but that may not be an available option for you.<br>
<br>
Chip H.<br>

 
Hmmm...<br>
<br>
I would suggest that if you get to this point - it's time to use a little database.<br>
<br>
Don't waste your time shuffling data about - it's already been done and far better than most of us could do it. Easy enough to read and write to a database file in VB - even I managed it...<br>
<br>
Mike <p>Mike Lacey<br><a href=mailto:Mike_Lacey@Cargill.Com>Mike_Lacey@Cargill.Com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top