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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Write data to a specific line in a textfile

Status
Not open for further replies.

kalle82

Technical User
Apr 2, 2009
163
SE
Hi!

Been doing some wonderful coding thanks to you guys here on the forum!

So if you read any of my other posts you can see I'm in the process of learning everything there is about creating .ini files, reading and writing data to them and ordinary tex files aswell.

Now I have this log file with data like this

Code:
#2011-07-01#,kattsanden testas nu och den ska funka!,2011-07-01
#2011-07-01#,testar igen,2011-07-02
#2011-07-01#,nu ska vi se om det funkar!,2011-07-03
#2011-07-01#,nu ska vi se om det funkar!,2011-07-04
#2011-07-01#,nu ska vi se om det funkar!,2011-07-05

I have created a sub that loops down to the correct row, and extracts the last date.

Code:
Dim date1, loggen, date2 As String
    Open logfilename For Input Access Read As #1
        i = 1
        Do While i < therow
        
        Input #1, date1, loggen, date2
        
        i = i + 1
    Loop
       Input #1, date1, loggen, date2
       
       MsgBox (date2)
               
    Close #1

Now the thing is that I have to update the log as thing happens... Therefore I want to be able to write on a specific line.

How should i attack this?
 


Rename the file

OPEN Renamed for for READ
OPEN OldFileName for WRITE

READ the file

Change the appropriate data

WRITE to OldFile

KILL Renamed file.



Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Hmm! Can't I somehow open the file with write access loop down to the row in question and change the date to the new one?
 
Okay this was a bit harder than I thought... What about saving all the values into an array. Then update the array with the correct value and write back into the file?

 



I was using Read & Write in a genaric sense, NOT as a command.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top