This has got to be simple but I cannot see it. This is the code:
Output from text file:
I click btn_StartStop to start. The elapsed time starts from 1 hour instead of 0. Where is my mistake?
B4X:
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.SetFormStyle("UNIFIED")
MainForm.RootPane.LoadLayout("PiLogger") 'Load the layout file.
MainForm.Show
Timer1.Initialize("Timer1",1000) 'prepare timer
If File.IsDirectory(File.DirApp,"windsonic/") = False Then
File.MakeDir(File.DirApp,"windsonic/")
Log("Directory created!")
End If
FileDirectory=File.DirApp & "\windsonic\"
Log(FileDirectory)
End Sub
Sub Timer1_Tick
Dim t, String1 As String
DateTime.TimeFormat="HH:mm:ss"
t = DateTime.Time(DateTime.Now)
Log(t)
ElapsedTime=DateTime.Time(DateTime.Now-StartTime) 'calculate elapsed time
lbl_ElapsedTime.Text=ElapsedTime 'update UI
'This is one line in text file
String1=t & "," & ElapsedTime & "," & lbl_Speed.Text & "," & lbl_Direction.Text & Chr(13)
Writer.WriteLine(String1) 'write to file
End Sub
Sub btn_StartStop_MouseClicked (EventData As MouseEvent)
If NewFileCreated=False Then
Return
End If
If btn_StartStop.Tag="0" Then 'Logger is off, turn on
btn_StartStop.Tag="1" 'set tag to on
lbl_LoggerStatus.Style="-fx-background-color: green" 'change background color
btn_StartStop.Text="Stop Logger" 'change button text
Timer1.Enabled=True 'start timer
DateTime.TimeFormat="HH:mm:ss"
StartTime=DateTime.Now
Else
btn_StartStop.Tag="0"
lbl_LoggerStatus.Style="-fx-background-color: red"
btn_StartStop.Text="Start Logger"
Timer1.Enabled=False
Writer.Close
End If
End Sub
Output from text file:
B4X:
13:56:32,01:00:01,0,45,227,0
13:56:33,01:00:02,0,45,227,0
13:56:34,01:00:03,0,45,227,0
13:56:35,01:00:04,0,45,227,0
13:56:36,01:00:05,0,45,227,0
13:56:37,01:00:06,0,45,227,0
13:56:38,01:00:07,0,45,227,0
13:56:39,01:00:08,0,45,227,0
13:56:40,01:00:09,0,45,227,0
13:56:41,01:00:10,0,45,227,0
I click btn_StartStop to start. The elapsed time starts from 1 hour instead of 0. Where is my mistake?