Hello to everyone, Im new to vb.net and right now I am developing a program that its like a agenda where the user sets the date and the time do be remembered of the task the he has to do. Im storing the tasks in a txt file. The part when I set the time to, for example 21:30, a msgbox pops out saying "Alarm".But Im having trouble with the date, it gives an error every time I save the task into the txt file with the date on it.

So how can I see if the date of the computer its equal to the date in the txt file?

Heres the code that i have made:

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

    time_day = TimeOfDay.TimeOfDay.ToString
    date_day = Date.Today.ToLongDateString

End Sub



Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick

    Dim FILE_NAME As String = "C:\Users\Guilherme\Documents\database\data_base_tasks.txt"

    If System.IO.File.Exists(FILE_NAME) = True Then

        Dim objReader As New System.IO.StreamReader(FILE_NAME)

        Do While objReader.Peek() <> -1
            If objReader.ReadLine.Contains(date_day) And objReader.ReadLine.Contains(time_day) Then
                MsgBox("Alarm")
            End If
        Loop

    Else

        MsgBox("File Does Not Exist")

    End If

End Sub

Here buddy:

Public Class MyForm

    Private Sub MyForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim MyDate As String = Date.Today.ToLongDateString
        Dim MyTimeSpan As New TimeSpan
        MyTimeSpan = TimeOfDay.TimeOfDay + New TimeSpan(0, 0, 5)
        My.Computer.FileSystem.WriteAllText("MyFile.txt", MyDate & " - " & MyTimeSpan.ToString, False)
        MyTimer.Interval = 750 'Don't make the Interval below 500 because one second is 1000 intervals.
        'If it is less then 500 then it will make multiple MessageBoxes show up.
        MyTimer.Start()
    End Sub

    Private Sub MyTimer_Tick(sender As Object, e As EventArgs) Handles MyTimer.Tick
        Dim MyDate As String = Date.Today.ToLongDateString
        Dim MyTime As String = TimeOfDay.TimeOfDay.ToString
        Dim MyFileContents As String = My.Computer.FileSystem.ReadAllText("MyFile.txt")
        If MyFileContents.Contains(MyDate) And MyFileContents.Contains(MyTime) Then
            MessageBox.Show("Success")
        End If
    End Sub
End Class

On the MyForm_Load I did this:

            MyTimeSpan = TimeOfDay.TimeOfDay + New TimeSpan(0, 0, 5)

This means the MessageBox will appear five seconds after the launch of the application.
And the timer reads and checks MyFile.txt to make sure it contains the correct times.

Checked, works.

Pride, thank you for helping me! The code that you made helped me a lot, i had to made some alterations to ajust to what my program has to do and now its working very well! :)

No problem. :)

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.