Timer calculation

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


  RemainingTime=FinishTime.totalseconds - d.TotalSeconds
  
  Label3.text="Remaining Time:" + str(RemainingTime)

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

For some reason, the Timer does not see the other variables. The variables are stored in a module and all of them are global.

What could be the reason for that? I’ve never had a problem like this before.

Thank you,

Val

[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


  RemainingTime=FinishTime.totalseconds - d.TotalSeconds
  
  Label3.text="Remaining Time:" + str(RemainingTime)

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.

Hi, Michel,

Here is the code


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.

Are you sure, that FinishTime is not Nil in the timer’s Action event?

  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.

[quote=178642:@Valeriy Kozmenko][code]
Dim d As Date = Date.Now

RemainingTime.totalseconds=FinishTime.totalseconds// - d.TotalSecond

Label3.text="Remaining Time: " + str(RemainingTime.totalseconds )
[/code]

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.

May I suggest that instead of what you are doing, you look into Microseconds
http://documentation.xojo.com/index.php/Microseconds

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.

Michel,

Thank you for suggesting using Microseconds. It works really we’ll.

Thank you,

Val