New Timer

I’m having trouble getting a timer to work.

I’ve created a class and named it “timStartup” with a Super of “Timer”. And set an action to display a message box.

In my App Open event, I have the following code:

Dim timStartupB As New App.timStartup timStartupB.Mode = Timer.ModeSingle timStartupB.Period = 1000 timStartupB.Enabled = True

But the timer does not run. I’m not sure what I’m missing.

Thanks-
Adam

Well since you can’t declare a class inside App I suspect there’s one issue in this line

Dim timStartupB As New App.timStartup
This probably should be

Dim timStartupB As New timStartup timStartupB.Mode = Timer.ModeSingle timStartupB.Period = 1000 timStartupB.Enabled = True
this assumes that timStartUpB is a property on the app class & not a local variable.

I’m not quite sure of what you mean “And set an action to display a message box.”
In your subclass action event you implemented the Action event ?
Or do you mean something else ?

Thanks for reply.

Still no luck when I remove “App.”

Inside the timStartup, I added an Event Handler for “Action”. In there I put

msgbox("hi")

But that msgbox never comes up.

Make timStartUpB a PROPERTY on your app class
When you have

Dim timStartupB As New timStartup
its a local variable and that variable gets removed BEFORE the timer has a chance to run 1 second so it never has a chance to show the message
Then change the code in App.Open to

  timStartupB = New App.timStartup
  timStartupB.Mode = Timer.ModeSingle
  timStartupB.Period = 1000
  timStartupB.Enabled = True

This way the timer gets created & does NOT go out of scope before its done its thing

Beautiful. Thank you!

The various users guides (in PDF etc) are useful for explaining a lot of this stuff.
They’re accessible from the Help Menu in Xojo