Hi, I have created a countdown timer in my application. The problem with the timer is that it pauses when the user uses the other controls.
I am redesigning the countdown timer. When the user clicks the “Start” button the software records the StartTime and adds 30 min and saves the result as FinishTime.
Then, I want the timer to perform calculations of the remaining time every second
For some reason, the debugger throws the NillObjectException error even though I’ve explicitly declared d, FinishTime and StartTime as Date, and RemainingTime as Integer.
[quote=178619:@Valeriy Kozmenko]Hi, I have created a countdown timer in my application. The problem with the timer is that it pauses when the user uses the other controls.
I am redesigning the countdown timer. When the user clicks the “Start” button the software records the StartTime and adds 30 min and saves the result as FinishTime.
Then, I want the timer to perform calculations of the remaining time every second
For some reason, the debugger throws the NillObjectException error even though I’ve explicitly declared d, FinishTime and StartTime as Date, and RemainingTime as Integer.
Any advices?
Thank you in advance,
Val[/quote]
You haven’t posted all the code, but chances are you did not dim d, or it has the wrong scope.
Sub Action()
Dim d As New Date
RemainingTime.totalseconds=FinishTime.totalseconds - d.TotalSeconds
Label3.text="Remaining Time: " + str(RemainingTime.totalseconds )
End Sub
Still have the same problem. Frustrated - the code is very simple but again, the debugger throws the NilObjectException.
Dim d As Date = Date.Now
RemainingTime.totalseconds=FinishTime.totalseconds// - d.TotalSecond
Label3.text="Remaining Time: " + str(RemainingTime.totalseconds )
The debugger highlights Date.Now is says that this item does not exist.
The debugger highlights Date.Now is says that this item does not exist.[/quote]
This cannot work at all. You are using new framework date.now that belongs to Xojo.Core.Date together with the desktop date object, and nowhere are RemainingTime and FinishTime which you use like Date are initialized.
You seem to have trouble with the very basics of Date.
it provides a continuous feed of microseconds which you can use to calculate your countdown without any date object. To get seconds from that, just divide by 1000000.