Results 1 to 5 of 5

Thread: How to open a textfile for rewrite .

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2000
    Posts
    156
    when i'm writing the next code it overwrite the last file.
    i want to add a new data at the EOF .

    Open "c:\temp\lirlir.txt" For Output As #1
    Write #1, "lirlir", "lir"
    Close #1
    The MORE I get to know,
    I realize that I know NOTHING !

  2. #2
    Hyperactive Member
    Join Date
    Dec 1999
    Posts
    321

    Exclamation Append

    use this

    Code:
    Open "c:\temp\lirlir.txt" For Append As #1 
    Write #1, "lirlir", "lir" 
    Close #1
    Signed, Rodik ([email protected])
    Programmer,usesVB6ED
    ===========================
    Copyright©RodikCo,2002.

    Dont mind this signature ;] Its old

  3. #3
    Hyperactive Member
    Join Date
    May 2000
    Location
    Or
    Posts
    316
    You can do it two ways. Using the open method, you would use the following syntax:

    Code:
    Open "c:\temp\lirlir.txt" For Append As #1 
    Do while not EOF(1)
    Print #1,Text & vbcrlf  'Add the vbcrlf if you want a hard space after each line of text.
    Loop
    Close #1
    In the above example, you can use write, but only if you want the text to be written into the file with quote marks like
    "lir""lir"

    Or you could use the FilesystemObject

    Code:
    Dim fso, sTemp(1)
    
    Set fso=CreateObject("scripting.FileSystemObject")
    Set sTemp(0)=fso.getFile("c:\temp\lirlir.txt")
    Set sTemp(1)=sTemp(0).OpenAsTextStream(8,-2)
    sTemp(1).Write Text
    sTemp(1).Close
    Hope this helps

    (Using VB 6 SP 3)

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jun 2000
    Posts
    156

    Thumbs up Very helpfull tanks u both

    Very helpfull tanks u both
    The MORE I get to know,
    I realize that I know NOTHING !

  5. #5
    Guest
    if you dont want to use filesystem object, but you dont want the quotation marks, use print,

    Code:
    Print #FileNumber, Variable & "or text"

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