Results 1 to 3 of 3

Thread: Append text on the top of the current textfile? [RESOLVED]

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2002
    Posts
    665

    Question Append text on the top of the current textfile? [RESOLVED]

    I have a textfile, how can I append text on the TOP of the current textfile?
    Last edited by Pirre001; May 26th, 2005 at 10:03 AM. Reason: Resolved

  2. #2
    Fanatic Member vbasicgirl's Avatar
    Join Date
    Jan 2004
    Location
    Manchester, UK
    Posts
    1,016

    Re: Append text on the top of the current textfile?

    this is one way.
    VB Code:
    1. Dim str1 As String
    2.  
    3. Open "C:\yourfile.txt" For Binary As #1
    4.  str1 = Space$(LOF(1))
    5.  Get #1, 1, str1
    6.  Put #1, 1, Text1.Text & vbCrLf & str1
    7. Close #1

    casey.

  3. #3
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: Append text on the top of the current textfile?

    Try something like this:

    VB Code:
    1. Dim intFile As Integer
    2. Dim strFile As String
    3. intFile = FreeFile
    4.  
    5. Open "yourfile.txt" For Input as #intFile
    6.     strFile = Iinput(FileLen("yourfile.txt"), intFile)
    7. Close #intFile
    8.  
    9. strFile = "Some text here..." & vbNewLine & strFile
    10.  
    11. Open "yourfile.txt" For Binary Access Write As #intFree
    12.     Put #intFree, , strFile
    13. Close #intFree

    Cheers,

    RyanJ
    My Blog.

    Ryan Jones.

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