S Startup Active Member Licensed User Longtime User Feb 14, 2016 #1 I'm trying to use a starter module to declare and initialize process globals and initialize them in the starter module like this -- Code: Copy Sub Process_Globals Public Timer1 As Timer End Sub Sub Service_Create Timer1.Initialize("Timer1",2000) Timer1.Enabled=True End Sub yet in the main module where I have Code: Copy Sub Timer1_Tick Msgbox("Times Up","") Timer1.Enabled=False End Sub I get a "undeclared timer1 ... " message. How do I get the starter globals recognized in the main module?
I'm trying to use a starter module to declare and initialize process globals and initialize them in the starter module like this -- Code: Copy Sub Process_Globals Public Timer1 As Timer End Sub Sub Service_Create Timer1.Initialize("Timer1",2000) Timer1.Enabled=True End Sub yet in the main module where I have Code: Copy Sub Timer1_Tick Msgbox("Times Up","") Timer1.Enabled=False End Sub I get a "undeclared timer1 ... " message. How do I get the starter globals recognized in the main module?
Erel B4X founder Staff member Licensed User Longtime User Feb 14, 2016 #2 The correct code: Code: Copy Starter.Timer1.Enabled = True Upvote 0
DonManfred Expert Licensed User Longtime User Feb 14, 2016 #3 Maybe i´m wrong but shouldn´t the timer tick not be in the starter service instead of the main module? Upvote 0
Maybe i´m wrong but shouldn´t the timer tick not be in the starter service instead of the main module?
S Startup Active Member Licensed User Longtime User Feb 14, 2016 #4 Erel said: The correct code: Code: Copy Starter.Timer1.Enabled = True Click to expand... OK Erel that gets rid of the "undeclared" message. But I have to move the initialization to the main module to make it work but I read that initialization should be in the starter service module? I also tried to move the timer tick into the starter service per Don Manfred's post below but that didn't work for me . I'm just using this simple program to learn what to put in the starter module and what in the main. Here is my code in zip file. This works but I don't think it is right way (or elegant way - initialization should be in the starter modue?). Or is this the best way to do it? Thanks! Attachments MyServiceTest.zip MyServiceTest.zip 6.5 KB · Views: 344 Upvote 0
Erel said: The correct code: Code: Copy Starter.Timer1.Enabled = True Click to expand... OK Erel that gets rid of the "undeclared" message. But I have to move the initialization to the main module to make it work but I read that initialization should be in the starter service module? I also tried to move the timer tick into the starter service per Don Manfred's post below but that didn't work for me . I'm just using this simple program to learn what to put in the starter module and what in the main. Here is my code in zip file. This works but I don't think it is right way (or elegant way - initialization should be in the starter modue?). Or is this the best way to do it? Thanks!
Erel B4X founder Staff member Licensed User Longtime User Feb 15, 2016 #5 Technically it is not important whether the timer is declared in the process_globals of the starter service or the main activity. The result is exactly the same. If you want to use the timer from the main module then it should be private and declared in the main module, and initialized when FirstTime is true. If you want to use it from the starter service then it should be private and declared in the starter service, and initialized in Service_Create. Both options are good. Upvote 0
Technically it is not important whether the timer is declared in the process_globals of the starter service or the main activity. The result is exactly the same. If you want to use the timer from the main module then it should be private and declared in the main module, and initialized when FirstTime is true. If you want to use it from the starter service then it should be private and declared in the starter service, and initialized in Service_Create. Both options are good.