Android Question StartServiceAt(Me, Min(NextTimeInstance?

anOparator

Active Member
Licensed User
Longtime User
B4X:
Sub Service_Start
StartServiceAt(Me,  Min(NextTimeInstance(8, 01), NextTimeInstance(12, 01)), True
CallSub(Main, "button1_Click")
This instruction helps by eliminating 2 services but gives a 'Too many parameters' error when adding a third NextTimeInstance(17, 01).

What is this 'Min' keyword, and what approach could I take to add 6 time instances to StartServicesAt?
 

JordiCP

Expert
Licensed User
Longtime User
Min() only works with 2 arguments

The ugly but effective way for 6 arguments could be nesting the calls (NTIn is NextTimeInstance(...))
B4X:
Min(Min(Min(NTI1,NTI2),Min(NTI3,NTI4)),Min(NTI5,NTI6))

or you could also make your myMin Sub passing a list of all the NTIs as a parameter

B4X:
Sub myMin( longValuesList as List)as long
   Dim minValue as Long = longValueList.Get(0) 'feed it with an existing value in the list
   for each val as Long in longValueList
      minValue=min(val,minValue)
   Next
   return minValue
End Sub
 
Upvote 0

anOparator

Active Member
Licensed User
Longtime User
ugly is good, and I hope this can be done , but:
B4X:
Min(NextTimeInstance (8, 01)
refers to 8:01 A.M.
I get 'Invalid number of parentheses' errors no matter what I try.
Am just wanting to give NextTimeInstance 6 seperate event times.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Am just wanting to give NextTimeInstance 6 seperate event times.
You should write a small sub which does the calculation and return just the correct value in this case.

Note that the sub from @JordiCP can handle multiple times... 1, 2, 100
 
Upvote 0

anOparator

Active Member
Licensed User
Longtime User
very ugly having 8 or more event_Clicks needed.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
what approach could I take to add 6 time instances to StartServicesAt?
You only can set the NEXT occurence.
If you have X times (maybe 6, 8). Calculate the time of the NEXT COMING event and set startserviceat to this time.
If your service running the next time and want the next event. Recalulate it again and again set the startservicdat to the next time it should raise.
 
Upvote 0

anOparator

Active Member
Licensed User
Longtime User
You only can set the NEXT occurence.
If you have X times (maybe 6, 8). Calculate the time of the NEXT COMING event and set startserviceat to this time.
If your service running the next time and want the next event. Recalulate it again and again set the startservicdat to the next time it should raise.
I hope I know what is being said, I will make a list of 8 times for my event and increment the time with each Click. (if that is what is meant by 'calculate).
thanks for the pointers.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
if that is what is meant by 'calculate
Not exactly.

Try to understand what the sub from @JordiCP really does. Create a list with 8 different times in the future. call the method and check which of them are giving back. Why it is exct this value?
 
Upvote 0
Top