Results 1 to 6 of 6

Thread: writeline overwrites my file, instead of appending [resolved]

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2002
    Location
    southwest pennsylvania
    Posts
    65

    writeline overwrites my file, instead of appending [resolved]

    i have a list of accounts in a txt file that goes like this:
    username
    password
    username
    password
    ...and so on.
    if a user makes a new account, i want it to append to the end of the file.
    here is the code:
    VB Code:
    1. Dim sw As StreamWriter = New StreamWriter("users.txt")
    2. sw.Write(name)
    3. sw.Write(pass)
    4. sw.Close()

    but the text only erases my file and writes the name and pass
    Last edited by joeframbach; Dec 30th, 2002 at 09:49 PM.
    if you choose not to decide you still have made a choice!

    RUSH rocks!

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    try this :
    VB Code:
    1. Function SaveTextFile(ByVal FilePath As String, ByVal FileContent As String, _
    2.     Optional ByVal Append As Boolean = False) As Boolean
    3.  
    4.     Dim sw As System.IO.StreamWriter
    5.     Try
    6.         sw = New System.IO.StreamWriter(FilePath, Append)
    7.         sw.Write(FileContent)
    8.         Return True
    9.     Catch e As Exception
    10.         Return False
    11.     Finally
    12.         If Not sw Is Nothing Then sw.Close()
    13.     End Try
    14. End Function

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Dec 2002
    Location
    southwest pennsylvania
    Posts
    65
    i shouldve mentioned earlier: im new to vb!

    i have absolutely no clue what that does....
    if you choose not to decide you still have made a choice!

    RUSH rocks!

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    comment inside the project.
    Attached Files Attached Files

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Dec 2002
    Location
    southwest pennsylvania
    Posts
    65
    thank you VERY much!
    if you choose not to decide you still have made a choice!

    RUSH rocks!

  6. #6
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Don't mention it !

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