|
-
Jan 24th, 2000, 11:41 PM
#1
Thread Starter
Hyperactive Member
I need to open a file and both read and write to it. It's a CSV file that I need to look through to see if a line matches the one I need to add and then write the changes to that line. I can open a file to read or to write but I don't know how to do both.
-
Jan 24th, 2000, 11:49 PM
#2
Hyperactive Member
Use this syntax
Open "myfile.csv" For Append Access Read Write As #1
Hope this helps
-
Jan 25th, 2000, 12:18 PM
#3
Thread Starter
Hyperactive Member
Rick, It will let me open it but it goes to end of file. I need to search through the file before I write to it.
I use:
Do Until EOF(intFreeFile)
Line Input #intFreeFile, strLine
If Mid(strLine, 1, InStr(1, strLine, ",") - 1) = intRecordID Then
Exit Do
End If
Loop
I need to search through the file to see if there's a record already exisiting. Using the append doesn't allow me to with this code because the EOF is always TRUE. Any other ideas or is there different code I can use for this?
-
Jan 25th, 2000, 12:31 PM
#4
Hyperactive Member
I see the problem, why dont you create a copy of the file (line by line) as you are searching, apply the edits (or add ins) to the new copy. Therefore you can open the old one as INPUT and the new one as OUTPUT.
Bit messy but will do the job.
[This message has been edited by Rick H (edited 01-25-2000).]
-
Jan 25th, 2000, 12:36 PM
#5
Thread Starter
Hyperactive Member
Yuck. :-( I've been thinking about that too. It would work, but I was really hoping for another, smoother and less resource-dependable method. I'm afraid I'll probably have to do it though :-(. Thanks for the help.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|