File Write(Append)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aviraldg
    New Member
    • Sep 2007
    • 21

    File Write(Append)

    How do I write data at the end of a file (size unknown) in binary mode ?
  • QVeen72
    Recognized Expert Top Contributor
    • Oct 2006
    • 1445

    #2
    Hi,

    By default when you open the file, whatever you add will be added after the last character.
    Open the file, and a vbCrLF and write the text say:

    [code=vb]
    Dim FN As Long
    i = i + 1
    FN = FreeFile
    Open "C:\MyText. txt" For Append As FN
    Print #FN, vbCrLF & "New Line Added From VB6 Program"
    Close #FN
    [/code]


    First time you have to add vbCrLF, if you want to add few more lines immediately, no need to cancatenate text with vbcrLF...they will be printed in next line..

    Regards
    Veena
    Last edited by Killer42; Nov 5 '07, 01:46 AM.

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      Originally posted by aviraldg
      How do I write data at the end of a file (size unknown) in binary mode ?
      Sorry aviraldg, apparently QVeen72 didn't finish reading the question. To append to a file in binary mode, you have to do two things. First, open with the proper access (both read and write). Second, position to the end of the file before writing.

      For example...
      [CODE=VB]Open "TheFile.xx x" For Binary Access Read Write As #1
      Seek #1, Lof(#1)
      Put #1,,YourData
      [/CODE]
      Note: if you want, you can skip the reposition step (the Seek), and specify the position at which to write in the Put statement. (The position is the missing parameter between the commas in the above example.)
      Last edited by Killer42; Nov 5 '07, 01:54 AM.

      Comment

      • aviraldg
        New Member
        • Sep 2007
        • 21

        #4
        Thanks for the help ! Expect to see Quiz Creator Soon!

        Comment

        Working...