开发者

Writing to a specific line of a file

开发者 https://www.devze.com 2022-12-28 02:23 出处:网络
I have a .dat file with data like this in \"James\",\"Project5\",\"15/05/2010\",\"3\" \"Matt\",\"Project1\",\"01/05/2010\",\"5\"

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"
"M开发者_JAVA技巧att","Project3","03/05/2010","4"

Any help would be fantastic!


  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.


You could use an ini file for your schema. For example:

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

精彩评论

暂无评论...
验证码 换一张
取 消