read all the data into an array.
edit the data u want from that particular array
write back the entire array into the same file overwriting everything.
Main Topics
Browse All Topicshere is my dilemma, I have a file with data seperated by {}'s and then again by carriage returns. example
{person 1}{height}{weight}{haircol
{person 2}{height}{weight}{haircol
and so on. I wrote a program to read the file in and i can now browse through it and make changes however i'm having trouble on how i can write these changes back. I want to have the file write the data back based on the persons name, so i figured out how to strip that out so i know what line to write back on.
I tried a random access file and that didn't work because all of the records have to be the same length, a sequential file writes back in text strings with the ""'s around everything, and appending wont work becuase i want to edit the data that is already there. any ideas would be really helpful.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
try this:
Use ReadData() to load all the data into the collection. You'll have all the data in your collection object. Use WriteData() to write it back into the text file. Whatever editing u perform will be only on the collection object only and you have the option of providing a "cancel edit" also by which you can revert back to your original data by just clearing the collection and calling the ReadData() again.
Dim objFileSystemObject As Scripting.FileSystemObject
Dim objTextStream As Scripting.TextStream
Dim objData As Collection
Dim strFileName As String
Private Sub Form_Load()
Set objFileSystemObject = CreateObject("Scripting.Fi
Set objData = New Collection
strFileName = "c:\test.txt"
End Sub
Private Sub Form_Unload(Cancel As Integer)
On Error Resume Next
objTextStream.Close
Set objTextStream = Nothing
Set objFileSystemObject = Nothing
Set objData = Nothing
End Sub
Function ReadData()
Set objTextStream = objFileSystemObject.OpenTe
While Not objTextStream.AtEndOfLine
objData.Add objTextStream.ReadLine
Wend
Set objTextStream = Nothing
End Function
Function WriteData()
Dim i As Long
Set objTextStream = objFileSystemObject.Create
For i = 1 To objData.Count
objTextStream.WriteLine objData.Item(i)
Next
Set objTextStream = Nothing
End Function
cheers,
srimanth.
Business Accounts
Answer for Membership
by: AzraSoundPosted on 2003-09-30 at 06:54:02ID: 9459293
You have to write the entire file back, and use the Print command instead of the Write command to avoid the apostrophes around everything.