Results 1 to 2 of 2

Thread: read-write-save txt file

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2009
    Location
    Toronto, Canada
    Posts
    76

    read-write-save txt file

    Hi Guys, ( used VB-6 )

    Opening file, no problem here.
    Adding next lines to existing file creating me a problem.
    To fully open file with all lines in it works OK.


    1. Dim sFileText as String
    2. Dim iFileNo as Integer
    3. iFileNo = FreeFile

    4. 'open the file for reading
    5. Open "C:\Test.txt" For Input As #iFileNo
    6.
    8. 'read the file until the end
    9. Do While Not EOF(iFileNo)
    10. Input #iFileNo, sFileText
    11. 'show all what is in the file
    12. Text1.text = sFileText
    13. Loop
    14.
    15. 'close the file
    16. Close #iFileNo

    Done,

    Having the file fully open and load into the Text1.text box.
    Now is the time to add the next line from the Text2.text.
    Part of the program does conduct a series of operations based on keyboard input
    and when all this is completed writing NEW LINE from text2.box
    must be ADD and SAVE ALL not just the last line from text2 box
    and delete rest overrating this existing file.
    Any assistance on the matter would be greatly appreciated.
    Thanks,

  2. #2
    Addicted Member AnthonyGrimes's Avatar
    Join Date
    Sep 2008
    Location
    United States
    Posts
    131

    Re: read-write-save txt file

    I believe you would just have to open the file again for appending data.

    Code:
    Open "C:\Test.txt" For Append As #iFileNo
    Print #iFileNo, Text2.text
    Close #iFileNo

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