I’m trying to display the time elapsed since the Mac started, but only the minutes are correct, the number of days and the hours are wrong. Why ?
Dim jours, heures, minutes As Integer
Var lnTick As Double = System.Microseconds
heures = lnTick / 3600000
if heures > 23 then 'hours
jours = heures/24
heures = (heures mod 24)
else
jours = 0 'days
end
lnTick = (lnTick mod 3600000)
minutes = lnTick / 60000
//Secondes = (lnTick Mod 60000) / 1000
MsgBox "Your computer has been on for "+ Str(jours)+" days" + Str(heures)+" hours " + Str(minutes)+" minutes. "
Ultimately, I would like:
< 1 day: only display the hour and minutes
Sub Pressed() Handles Pressed
Var days As Integer = 0
Var hours As Integer = 0
Var minutes As Integer = 0
Var sec As Double = System.Microseconds / 1000000.0 ' 1 sec is 1000000 µs
While sec > 0.0
If sec >= 3600.0 * 24.0 Then
sec = sec - 3600.0 * 24.0
days = days + 1
ElseIf sec >= 3600.0 Then
sec = sec - 3600.0
hours = hours + 1
ElseIf sec >= 60.0 Then
sec = sec - 60.0
minutes = minutes + 1
Else
sec = -1.0
End If
Wend
MsgBox "Your computer has been on for " + Str(days) + " days " + Str(hours) + " hours " + Str(minutes) + " minutes."
End Sub
There are occasions where this will return misleading information. The online docs do mention this issue. Basically, on Windows at least, a Restart and a Shutdown/Reboot re not the same. Tthe System.Microseconds value doesn’t get reset if the user has done a Shutdown. This is because (unless disabled in Widows settings) Windows saves a fast-start “environment” so it can start up faster when the machine is restarted. The microseconds from boot are saved in this environment and reloaded when starting. This is why you can turn on the machine, run the test, and have it report 8 days… from startup.
When the user does a Restart, it is a true restart and the entire system, including the microseconds from boot, are reset.
Macs may have the same situation or not. I don’t have a Mac to test with.
Var Total As Double=System.Microseconds/1000000
Var Seconds As Integer=Total mod 60
Total=(Total-Seconds)/60
Var Minutes as Integer=Total mod 60
Total=(Total-Minutes)/60
Var Hours As Integer=Total mod 24
Total=(Total-Hours)/24
Var Days As Integer=Total