tags:

views:

44

answers:

2

I have a .dat file with data like this in

"James","Project5","15/05/2010","3"
"Matt","Project1","01/05/2010","5"
"Ellie","Project5","24/04/2010","1"
"Ellie","Project2","10/05/2010","3"
"Matt","Project3","03/05/2010","4"

It gets written in with thise code.

Private Sub Command2_Click()
Open jobs For Append As #1
Write #1, Combo1, Combo3, Combo2, Text3
Close #1
End Sub

I instead would like to write it to the file so that if a persons name is already in the file then it would just put the data in the file, under their that is already there but without the name. I can't figure out how to do this but this is what I would like it to end up like.

"James","Project5","15/05/2010","3"
"Matt","Project1","01/05/2010","5"
"Ellie","Project5","24/04/2010","1"
"Project2","10/05/2010","3"
"Matt","Project3","03/05/2010","4"

Any help would be fantastic!

+2  A: 
  1. First read in the whole file into memory and store it as an array (read it in as one long string and the Split it on vbNewLine).

  2. Then loop through the array and do your changes.

  3. Write the data to a temporary filename.

  4. Replace the original file with the temporary file. FSO (File System Objects) have some easy to use functions to delete and move files.

ho1
@ho don't forget to split on commas. It might be better to create an object.
Gutzofter
Well, I see the split on commas as part of step 2. But I agree that I'd probably end up creating an object to do the work.
ho1
A: 

You could use an ini file for your schema

[James]
project1=01/05/2010,5
project2=24/04/2010,1

Cidtek