how to refresh certain data every midnight?

konovalov

Member
Licensed User
Longtime User
I'm trying to set data that the user has put in edittext's back to 0 every midnight so that the next day he/she can put in new information and save the information to other edittexts. But I don't know how to make this work. I tried startserviceat, but I cannot seem to make it work so that it starts every midnight.
B4X:
StartServiceAt(AlarmService, DateTime.now, True)
This works fine, but is there a way to make datetime.now into datetime.time(0:00) or something, instead of datetime.now + 10*1000?
I'm fairly new to b4a and I couldn't figure it out with other threads.
sorry if this should be somewhere else on the forum or if it already exists.
Any help would be much appreciated :D
 

r2d4

Member
Licensed User
Longtime User
I think you have to do this otherwise:

Run a "observer" service (that checks if it is midnight) that calls a function that makes your settings.
 
Upvote 0

konovalov

Member
Licensed User
Longtime User
what do you mean by an observer service? *-)
I can't come up with anything that checks the time, other than that startserviceat :$
 
Upvote 0

DouglasNYoung

Active Member
Licensed User
Longtime User
I don't think you need anything fancy like an observer service. Simply store a variable of the current date to a file and check it every time the system is accessed and if it is a different date then reset the date. This also caters for the event where the user does not access the system for a few days,

Cheers,
Douglas
 
Upvote 0

konovalov

Member
Licensed User
Longtime User
B4X:
label2bm.Text = DateTime.Date(DateTime.Now)
   
   ReadTextReader1date 'here it returns saved date to label5tm
   
   If label2bm.Text = label5bm.Text Then
      Else

what do I do wrong, there are no errors but it just doesn't work. :(
also my label5bm, where it returns the saved date from the other label, is not a date but a time, though I have set datetime.dateformat
 
Upvote 0

konovalov

Member
Licensed User
Longtime User
B4X:
Sub ReadTextReader1date 'datum
    Dim TextReader1 As TextReader
   If File.Exists(File.DirDefaultExternal, "date.txt") = False Then
         WriteTextWriter1date
   Else
    TextReader1.Initialize(File.OpenInput(File.DirdefaultExternal, "date.txt"))
   Dim line As String
    line = TextReader1.ReadLine
   label5bm.Text = line
    TextReader1.Close
   End If

End Sub

btw this is the code where it retrieves the saved date :)
 
Upvote 0

konovalov

Member
Licensed User
Longtime User
B4X:
Sub WriteTextWriter1date 'datum
    Dim TextWriter1 As TextWriter
    TextWriter1.Initialize(File.OpenOutput(File.DirdefaultExternal, "date.txt", False))
    TextWriter1.WriteLine(DateTime.Date(DateTime.Now))
    TextWriter1.Close
End Sub

Do I need to set datetime.dateformat here also? because it saves the date but retrieves it as time.
And is this the problem, because it just doesn't seem to see if the date is different or the same in the 2 lables
 
Upvote 0

konovalov

Member
Licensed User
Longtime User
this is what I get, the left label parses the date, but when you save it to a textfile and retrieve it in the right label, that one only gives the time.

B4X:
If label2bm.Text = label5bm.Text Then
      Msgbox("ze zijn gelijk", "ze zijn gelijk")
      Else
                ...
it is ok if I put this in activity_create?
but I don't understand why it doesn't even show me the messagebox :(
it won't parse the code when they are different but it does not give me the messagebox either.
 

Attachments

  • Naamloos.png
    Naamloos.png
    57.6 KB · Views: 164
Upvote 0

konovalov

Member
Licensed User
Longtime User
it might be a little messy, but all the textwriters and readers are at the bottom
 

Attachments

  • project by konovalov.zip
    14.7 KB · Views: 158
Upvote 0
Top