Jump to content

[Resolvido] Verificar data num ficheiro txt


gui09

Recommended Posts

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 by ribeiro55
Link to comment
Share on other sites

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.