gui09 Posted July 22, 2012 at 08:07 AM Report Share #469619 Posted July 22, 2012 at 08:07 AM (edited) Bom dia a todos, neste momento estou a desenvolver um programa onde o utilizador define uma tarefa para uma certa data e hora. As tarefas estão a ser armazenada num ficheiro txt. Pelo método de ler linha a linha consegui que uma msgbox aparece-se a dizer "Alarm" ao definir uma certa hora, mas estou com problemas em comparar se a data do computador é igual à data que está no txt, pois se eu tento comparar a data e as horas a msgbox não aparece. Já tentei comparar a data do txt com date e datetimepicker. Não consigo lembrar-me de mais nada para isto dar bem. Aqui está o código: Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick time_day = TimeOfDay.ToString date_day = DateTimePicker1.Value.Date 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) Dim objreader1 As New System.IO.StreamReader(FILE_NAME) Do While objReader.Peek() <> -1 If objReader.ReadLine.Contains(DateTimePicker1.Value.Date.ToString) And objreader1.ReadLine.Contains(time_day) Then MsgBox("Alarm") End If Loop Else MsgBox("File Does Not Exist") End If End Sub Edited July 22, 2012 at 09:36 PM by ribeiro55 Link to comment Share on other sites More sharing options...
ribeiro55 Posted July 22, 2012 at 09:46 PM Report Share #469684 Posted July 22, 2012 at 09:46 PM 1 - Para que são os dois StreamReaders ao mesmo ficheiro? 2 - Usa breakpoints (F9) e percebe, em execução, quais são os valores que estão a chegar e que estão a ser testados. 3 - Qual é o formato das linhas do ficheiro? Repara que a representação string de uma DateTime e do TimeOfDay são completamente diferentes: Datetime = 22-07-2012 22:44:26 TimeOfDay = 22:44:26.1612521 Nem estou a olhar para a tua lógica de comparação, mas o mais certo é estares a tentar comparar algo que não tem nada a haver um com o outro. Also, ReadLine.Contains não é uma boa ideia. Novamente, qual é o formato das linhas do ficheiro? Considera delimitadores. 4 - Fecha os streams! Sérgio Ribeiro "Great coders aren't born. They're compiled and released""Expert coders do not need a keyboard. They just throw magnets at the RAM chips" Link to comment Share on other sites More sharing options...
gui09 Posted July 23, 2012 at 10:11 AM Author Report Share #469725 Posted July 23, 2012 at 10:11 AM Bom dia ribeiro55, obrigado por teres respondido ao meu post e por teres oferecido ajuda para resolver a minha dúvida. Estive a rever o código e consegui resolver o problema 🙂 , o meu programa já faz o que eu queria que ele fizesse. Novamente obrigado por teres ajudado 🙂 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now