I'm a brand new B4A user, and I'm trying to create a program that calculates the difference between two times. Unfortunately, most likely due to something I'm doing wrong, the difference is 10 hours too high.
I've simplified the code down to a single button on the screen that toggles between on and off, and when it toggles off, it displays the elapsed time. If I wait, say, 5 seconds, the time shows as 10:00:05 instead of 00:00:05
Can anyone please help me see what I've done wrong?
Thanks, Peter
I've simplified the code down to a single button on the screen that toggles between on and off, and when it toggles off, it displays the elapsed time. If I wait, say, 5 seconds, the time shows as 10:00:05 instead of 00:00:05
Can anyone please help me see what I've done wrong?
B4X:
#Region Project Attributes
#ApplicationLabel: Test Program
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
Dim StartTime As Long ' Date/Time that user clicked ON
Dim StopTime As Long ' Date/Time that user clicked OFF
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Private btnStartStop As Button
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Main")
DateTime.DateFormat = DateTime.DeviceDefaultDateFormat
btnStartStop.TextColor = Colors.Black
btnStartStop.Color = Colors.Green
btnStartStop.Text = "ON"
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub btnStartStop_Click
Dim x As String
If btnStartStop.Text = "ON" Then
StartTime = DateTime.Now
x = "ON at " & DateTime.Date(StartTime) & " " & DateTime.Time(StartTime)
ToastMessageShow(x, True)
btnStartStop.TextColor = Colors.Black
btnStartStop.Color = Colors.Red
btnStartStop.Text = "OFF"
Else
StopTime = DateTime.Now
x = "OFF at " & DateTime.Date(StopTime) & " " & DateTime.Time(StopTime) & CRLF & "Duration: " & DateTime.Time(StopTime - StartTime)
ToastMessageShow(x, True)
btnStartStop.TextColor = Colors.Black
btnStartStop.Color = Colors.Green
btnStartStop.Text = "ON"
End If
End Sub
Thanks, Peter