Hello to everyone, Im a beginner in vb.net and currently Im developing a "reminder" program, the user inserts a task that he as to do, the date and the time to be remimbered! Im saving the task in a txt file like this, "Make dinner,Reminder,24-07-2012 18:31:00", but line by line, each task in a diferent line.
The insert of the task and the pop up of the alarm are working fine, but i have a problem and that is, when the alarm goes one showing the task to the user and for some reason he needs to change something in the task, for that I thought in finding the line that contains the name of the task( this part is working) and replace the whole line with the one that haves the changes made by the user ( this part isn't working). I searched on google and in here but i was unable to put it to work.

So, how can i do this?

Heres the code that i have:

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        Dim line4, line5 As String
        For Each line As String In IO.File.ReadAllLines("C:\Users\Guilherme\Documents\database\data_base_tasks.txt")
            If line.Contains(TextBox3.Text) Then
                '  MsgBox("Found line" & line) this was to see if the line was found and it works
                line4 = line
                line5 = line4.Replace(line, TextBox1.Text & "," & TextBox2.Text & "," & DateTimePicker1.Value.ToShortDateString & " " & TextBox5.Text & ":00" & "," & TextBox4.Text & vbCrLf)
            End If
        Next
    End Sub

You'll have to read all of the lines into an array, modify the requested line, then write the array back out to the file. All you are doing is modifying the line in memory.

Dim lines() as String = IO.File.ReadAllLines(MYFILE)

For i As Integer = 0 to Ubound(lines)
    If lines(i).Contains(...
        lines(i) = 'new value of line
        Exit For
    End If
Next

IO.File.WriteAllLines(MYFILE,lines)

Reverend Jim, thank you for helping me with this! Now its all working well :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.