A apty Active Member Licensed User Longtime User May 22, 2014 #1 Is it possible to loop between time? e.g i want to write to a file from 2pm to 4pm. I want to stop writing when it reaches 4pm. Any suggestions will be appreciated.
Is it possible to loop between time? e.g i want to write to a file from 2pm to 4pm. I want to stop writing when it reaches 4pm. Any suggestions will be appreciated.
Erel B4X founder Staff member Licensed User Longtime User May 23, 2014 #2 You can use a timer for that. You will also need to prevent the device from sleeping with PhoneWakeState (and Service.StartForeground). Upvote 0
You can use a timer for that. You will also need to prevent the device from sleeping with PhoneWakeState (and Service.StartForeground).
A apty Active Member Licensed User Longtime User May 23, 2014 #3 Thanks Erel, I have been trying to use a timer but how do i loop say from 2pm to 4 pm? This is my code Code: Copy Sub timer1_Tick For i = 1 To 10 WriteTextWriter(Ax&","&Ay&","&Az&","&datetoday&","&lblBattery.Text&",IMEI="&imei) Next End Sub If i use an if statement, the statement keeps executing even after 4pm. Also, i tried with a service and the service doesn't stop at 4pm, it still writes the file.Please help. Upvote 0
Thanks Erel, I have been trying to use a timer but how do i loop say from 2pm to 4 pm? This is my code Code: Copy Sub timer1_Tick For i = 1 To 10 WriteTextWriter(Ax&","&Ay&","&Az&","&datetoday&","&lblBattery.Text&",IMEI="&imei) Next End Sub If i use an if statement, the statement keeps executing even after 4pm. Also, i tried with a service and the service doesn't stop at 4pm, it still writes the file.Please help.
Erel B4X founder Staff member Licensed User Longtime User May 23, 2014 #4 You will need to enable it on 2pm and disable it after 4pm. Upvote 0
A apty Active Member Licensed User Longtime User May 23, 2014 #6 Tried the code below but it doesnt work Code: Copy Sub Service_Start (StartingIntent As Intent) Dim timenow,timenow2 As String DateTime.TimeFormat="HH:mm" timenow=DateTime.time(DateTime.Now) timenow2=timenow.Replace(":",".") Dim starttime2 As Double=main.starttime2 Dim endtime2 As Double=main.endtime2 If timenow2>=starttime2 AND timenow2<=endtime2 Then timer1.Enabled=True Else timer1.Enabled=False End If End Sub The timer is not enabled If i remove the if statement, the timer works Upvote 0
Tried the code below but it doesnt work Code: Copy Sub Service_Start (StartingIntent As Intent) Dim timenow,timenow2 As String DateTime.TimeFormat="HH:mm" timenow=DateTime.time(DateTime.Now) timenow2=timenow.Replace(":",".") Dim starttime2 As Double=main.starttime2 Dim endtime2 As Double=main.endtime2 If timenow2>=starttime2 AND timenow2<=endtime2 Then timer1.Enabled=True Else timer1.Enabled=False End If End Sub The timer is not enabled If i remove the if statement, the timer works
R RjCl Member Licensed User Longtime User May 24, 2014 #8 apty said: Please help Click to expand... try Code: Copy Do While timenow2 >= starttime2 AND timenow2 <= endtime2 write to file Loop ? Upvote 0
apty said: Please help Click to expand... try Code: Copy Do While timenow2 >= starttime2 AND timenow2 <= endtime2 write to file Loop ?
Erel B4X founder Staff member Licensed User Longtime User May 25, 2014 #9 There are many problems in your code. I recommend you to go over DateUtils tutorial. Which interval are you using for this timer? Upvote 0
There are many problems in your code. I recommend you to go over DateUtils tutorial. Which interval are you using for this timer?