Results 1 to 4 of 4

Thread: Text file (simple) [resolve]

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2003
    Posts
    91

    Text file (simple) [resolve]

    I want it to check for a text file, if it doesnt exist, create it and then write a line to it, if it does exist open it and write a line.
    Last edited by Synth3t1c; Jul 20th, 2004 at 07:15 PM.

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by Synth3t1c
    I want it to check for a text file, if it doesnt exist, create it and then write a line to it, if it does exist open it and write a line.
    Try this now :
    VB Code:
    1. Private Sub FileOperation(ByVal Pth As String)
    2.         Dim writr As StreamWriter
    3.         If File.Exists(Pth) Then
    4.             writr = New StreamWriter(Pth)
    5.             writr.WriteLine("File was there, and New Value was added")
    6.             MessageBox.Show("done")
    7.         Else
    8.             writr = New StreamWriter(Pth)
    9.             writr.WriteLine("File wasn't there, and New value was added")
    10.             MessageBox.Show("done")
    11.         End If
    12.         writr.Close()
    13.     End Sub

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Dec 2003
    Posts
    91
    it overwrites whats in the file...

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by Synth3t1c
    it overwrites whats in the file...
    In the first 'IF' case change this line :
    VB Code:
    1. writr = New StreamWriter(Pth)
    to
    VB Code:
    1. writr = New StreamWriter(Pth, True)
    .

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