Results 1 to 5 of 5

Thread: Help! File I/O problem

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    Calgary Alberta
    Posts
    359

    Post

    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.

  2. #2
    Hyperactive Member
    Join Date
    Jan 2000
    Location
    Gloucestershire, England
    Posts
    301

    Post

    Use this syntax

    Open "myfile.csv" For Append Access Read Write As #1

    Hope this helps

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    Calgary Alberta
    Posts
    359

    Post

    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?

  4. #4
    Hyperactive Member
    Join Date
    Jan 2000
    Location
    Gloucestershire, England
    Posts
    301

    Post

    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).]

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    Calgary Alberta
    Posts
    359

    Post

    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
  •  



Click Here to Expand Forum to Full Width