Results 1 to 4 of 4

Thread: Writing a new line to a file

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 1999
    Location
    Phoenix, az
    Posts
    1,517
    Well...

    A easy one.

    I want to write to
    an existing file, with
    out deleting the old
    contents. I just want to
    add a string like "Test"
    on the next line.


  2. #2
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    this example should help:

    Code:
    Option Explicit
    
    Private Sub Command1_Click()
    Static i As Integer
    Dim filename As String
    Dim fnum As Byte
    
    filename = "c:\ttt.txt"
    
    fnum = FreeFile
    Open filename For Append As fnum
      Print #fnum, "extra line " & i
    Close fnum
    
    i = i + 1
    
    End Sub
    Mark
    -------------------

  3. #3
    Addicted Member jeroenh's Avatar
    Join Date
    Aug 2000
    Location
    Rotterdam, Holland
    Posts
    201
    You could also use the Microsoft Scripting Runtime Library.

    Then your code would be like this

    Dim fsObject as new FileSystemObject
    dim fsTextStream as TextStream
    Set fsTextStream = fsObject.OpenTextFile("TestkFileName")
    fsTextStream.AtEndOfStream
    fsTextStream.WriteLine 'Place your line here
    fsTextStream.Close
    Set fsObject = Nothing
    Set fsTextStream = Nothing

    Catch you later,

    Jeroen Hoekemeijer
    Code:
    If 1 = 2 Then MajorError

  4. #4
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845

    Angry

    Yeah don't bother with my suggestion! it actually works.


    try jeroenh's which doesn't

    I could probably post a few hundred lines of code using APIs which does the same thing as well.

    After all, the more code the better eh?!!!!


    Mark
    -------------------

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